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

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

Location:
trunk/src/org/openstreetmap/josm/io
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.