8155516: Suppress warnings from uses of deprecated Class.newInstance langtools
authordarcy
Mon, 02 May 2016 18:10:36 -0700
changeset 37759 f0b5daef41b6
parent 37758 3ecf9b414e05
child 37760 cc50ee6a8454
8155516: Suppress warnings from uses of deprecated Class.newInstance langtools Reviewed-by: jjg
langtools/src/java.compiler/share/classes/javax/tools/ToolProvider.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Option.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java
langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java
--- a/langtools/src/java.compiler/share/classes/javax/tools/ToolProvider.java	Mon May 02 16:17:39 2016 -0700
+++ b/langtools/src/java.compiler/share/classes/javax/tools/ToolProvider.java	Mon May 02 18:10:36 2016 -0700
@@ -123,7 +123,9 @@
     private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) {
         if (useLegacy) {
             try {
-                return Class.forName(className, true, ClassLoader.getSystemClassLoader()).asSubclass(clazz).newInstance();
+                @SuppressWarnings("deprecation")
+                T result = Class.forName(className, true, ClassLoader.getSystemClassLoader()).asSubclass(clazz).newInstance();
+                return result;
             } catch (ReflectiveOperationException e) {
                 throw new Error(e);
             }
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon May 02 16:17:39 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon May 02 18:10:36 2016 -0700
@@ -282,6 +282,7 @@
 
         if (options.isSet(XPRINT)) {
             try {
+                @SuppressWarnings("deprecation")
                 Processor processor = PrintingProcessor.class.newInstance();
                 processorIterator = List.of(processor).iterator();
             } catch (Throwable t) {
@@ -549,8 +550,9 @@
                         try {
                             Class<?> processorClass = processorCL.loadClass(processorName);
                             ensureReadable(processorClass);
-                            processor =
-                                (Processor) (processorClass.newInstance());
+                            @SuppressWarnings("deprecation")
+                            Object tmp = processorClass.newInstance();
+                            processor = (Processor) tmp;
                         } catch (ClassNotFoundException cnfe) {
                             log.error("proc.processor.not.found", processorName);
                             return false;
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Option.java	Mon May 02 16:17:39 2016 -0700
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Option.java	Mon May 02 18:10:36 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -151,6 +151,7 @@
             // Construct transformer
             try {
                 Class<?> trCls = Class.forName(classname);
+                @SuppressWarnings("deprecation")
                 Transformer transformer = (Transformer) trCls.newInstance();
                 transformer.setExtra(extra);
                 helper.addTransformer(suffix, transformer);
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java	Mon May 02 16:17:39 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/taglets/TagletManager.java	Mon May 02 18:10:36 2016 -0700
@@ -246,6 +246,7 @@
             }
             tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
             Class<?> customTagClass = tagClassLoader.loadClass(classname);
+            @SuppressWarnings("deprecation")
             Object instance = customTagClass.newInstance();
             Taglet newLegacy = new UserTaglet((jdk.javadoc.doclet.taglet.Taglet)instance);
             String tname = newLegacy.getName();
--- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java	Mon May 02 16:17:39 2016 -0700
+++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/tool/Start.java	Mon May 02 18:10:36 2016 -0700
@@ -270,7 +270,9 @@
             initMessager();
             messager.setLocale(locale);
             try {
-                doclet = (Doclet) docletClass.newInstance();
+                @SuppressWarnings("deprecation")
+                Object o = docletClass.newInstance();
+                doclet = (Doclet) o;
             } catch (InstantiationException | IllegalAccessException exc) {
                 exc.printStackTrace();
                 if (!apiMode) {