Changeset 10208 in josm


Ignore:
Timestamp:
2016-05-14T02:38:41+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11924 - Java 9 - JDK-6850612 deprecates Class.newInstance() ==> replace it by Class.getConstructor().newInstance()

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r10044 r10208  
    954954                if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) {
    955955                    try {
    956                         UIManager.setLookAndFeel((LookAndFeel) klass.newInstance());
    957                     } catch (Exception ex) {
     956                        UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance());
     957                    } catch (ReflectiveOperationException ex) {
    958958                        warn("Cannot set Look and Feel: " + laf + ": "+ex.getMessage());
    959959                    }
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r9968 r10208  
    6565        for (final Class<? extends FileImporter> importerClass : importerNames) {
    6666            try {
    67                 FileImporter importer = importerClass.newInstance();
     67                FileImporter importer = importerClass.getConstructor().newInstance();
    6868                importers.add(importer);
    6969                MapView.addLayerChangeListener(importer);
    70             } catch (Exception e) {
     70            } catch (ReflectiveOperationException e) {
    7171                if (Main.isDebugEnabled()) {
    7272                    Main.debug(e.getMessage());
     
    106106        for (final Class<? extends FileExporter> exporterClass : exporterClasses) {
    107107            try {
    108                 FileExporter exporter = exporterClass.newInstance();
     108                FileExporter exporter = exporterClass.getConstructor().newInstance();
    109109                exporters.add(exporter);
    110110                MapView.addLayerChangeListener(exporter);
    111             } catch (Exception e) {
     111            } catch (ReflectiveOperationException e) {
    112112                if (Main.isDebugEnabled()) {
    113113                    Main.debug(e.getMessage());
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r10181 r10208  
    12091209        T structPrototype;
    12101210        try {
    1211             structPrototype = klass.newInstance();
    1212         } catch (InstantiationException | IllegalAccessException ex) {
     1211            structPrototype = klass.getConstructor().newInstance();
     1212        } catch (ReflectiveOperationException ex) {
    12131213            throw new RuntimeException(ex);
    12141214        }
     
    12581258        T struct = null;
    12591259        try {
    1260             struct = klass.newInstance();
    1261         } catch (InstantiationException | IllegalAccessException ex) {
     1260            struct = klass.getConstructor().newInstance();
     1261        } catch (ReflectiveOperationException ex) {
    12621262            throw new RuntimeException(ex);
    12631263        }
    12641264        for (Entry<String, String> key_value : hash.entrySet()) {
    1265             Object value = null;
     1265            Object value;
    12661266            Field f;
    12671267            try {
  • trunk/src/org/openstreetmap/josm/data/projection/proj/ClassProjFactory.java

    r9067 r10208  
    99    private final Class<? extends Proj> projClass;
    1010
     11    /**
     12     * Constructs a new {@code ClassProjFactory}.
     13     * @param projClass projection class
     14     */
    1115    public ClassProjFactory(Class<? extends Proj> projClass) {
    1216        this.projClass = projClass;
     
    1721        Proj proj = null;
    1822        try {
    19             proj = projClass.newInstance();
    20         } catch (InstantiationException | IllegalAccessException e) {
     23            proj = projClass.getConstructor().newInstance();
     24        } catch (ReflectiveOperationException e) {
    2125            throw new RuntimeException(e);
    2226        }
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r9989 r10208  
    136136        for (Class<Test> testClass : allAvailableTests) {
    137137            try {
    138                 allTestsMap.put(testClass.getName(), testClass.newInstance());
    139             } catch (Exception e) {
     138                allTestsMap.put(testClass.getName(), testClass.getConstructor().newInstance());
     139            } catch (ReflectiveOperationException e) {
    140140                Main.error(e);
    141141            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java

    r10001 r10208  
    220220            } else {
    221221                // create handler object
    222                 RequestHandler handler = handlerClass.newInstance();
     222                RequestHandler handler = handlerClass.getConstructor().newInstance();
    223223                try {
    224224                    handler.setCommand(command);
     
    243243        } catch (IOException ioe) {
    244244            Main.debug(Main.getErrorMessage(ioe));
    245         } catch (Exception e) {
     245        } catch (ReflectiveOperationException e) {
    246246            Main.error(e);
    247247            try {
     
    391391    public static String getHandlerInfoAsJSON(String cmd) {
    392392        try (StringWriter w = new StringWriter()) {
    393             PrintWriter r = new PrintWriter(w);
    394393            RequestHandler handler = null;
    395394            try {
    396395                Class<?> c = handlers.get(cmd);
    397396                if (c == null) return null;
    398                 handler = handlers.get(cmd).newInstance();
    399             } catch (InstantiationException | IllegalAccessException ex) {
     397                handler = handlers.get(cmd).getConstructor().newInstance();
     398            } catch (ReflectiveOperationException ex) {
    400399                Main.error(ex);
    401400                return null;
    402401            }
    403402
     403            PrintWriter r = new PrintWriter(w);
    404404            printJsonInfo(cmd, r, handler);
    405405            return w.toString();
     
    459459     * Reports HTML message with the description of all available commands
    460460     * @return HTML message with the description of all available commands
    461      * @throws IllegalAccessException if one handler class or its nullary constructor is not accessible.
    462      * @throws InstantiationException if one handler class represents an abstract class, an interface, an array class,
    463      * a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason.
    464      */
    465     public static String getUsageAsHtml() throws IllegalAccessException, InstantiationException {
     461     * @throws ReflectiveOperationException if a reflective operation fails for one handler class
     462     */
     463    public static String getUsageAsHtml() throws ReflectiveOperationException {
    466464        StringBuilder usage = new StringBuilder(1024);
    467465        for (Entry<String, Class<? extends RequestHandler>> handler : handlers.entrySet()) {
    468             RequestHandler sample = handler.getValue().newInstance();
     466            RequestHandler sample = handler.getValue().getConstructor().newInstance();
    469467            String[] mandatory = sample.getMandatoryParams();
    470468            String[] optional = sample.getOptionalParams();
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r9746 r10208  
    9999        SessionLayerImporter importer = null;
    100100        try {
    101             importer = importerClass.newInstance();
    102         } catch (InstantiationException | IllegalAccessException e) {
     101            importer = importerClass.getConstructor().newInstance();
     102        } catch (ReflectiveOperationException e) {
    103103            throw new RuntimeException(e);
    104104        }
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r9983 r10208  
    8383                Class<?> klass = mapping.get(qname).klass;
    8484                try {
    85                     current.push(klass.newInstance());
    86                 } catch (Exception e) {
     85                    current.push(klass.getConstructor().newInstance());
     86                } catch (ReflectiveOperationException e) {
    8787                    throwException(e);
    8888                }
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r8876 r10208  
    6868        TrustManager[] trustAllCerts = new TrustManager[] {
    6969            new X509TrustManager() {
     70                @Override
    7071                public X509Certificate[] getAcceptedIssuers() {
    7172                    return null;
    7273                }
    7374
     75                @Override
    7476                public void checkClientTrusted(X509Certificate[] certs, String authType) {
    7577                }
    7678
     79                @Override
    7780                public void checkServerTrusted(X509Certificate[] certs, String authType) {
    7881                }
     
    141144                }
    142145                assert responseBody.toString().contains(RequestProcessor.getUsageAsHtml());
    143             } catch (IllegalAccessException | InstantiationException e) {
     146            } catch (ReflectiveOperationException e) {
    144147                e.printStackTrace();
    145148                fail(e.getMessage());
Note: See TracChangeset for help on using the changeset viewer.