You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2018/09/11 17:42:52 UTC

svn commit: r1840595 - in /pivot/trunk: charts/src/org/apache/pivot/charts/ core/src/org/apache/pivot/beans/ core/src/org/apache/pivot/json/ core/src/org/apache/pivot/serialization/ core/src/org/apache/pivot/util/ wtk/src/org/apache/pivot/wtk/

Author: rwhitcomb
Date: Tue Sep 11 17:42:52 2018
New Revision: 1840595

URL: http://svn.apache.org/viewvc?rev=1840595&view=rev
Log:
PIVOT-1039:  Address the remaining deprecation warnings (about Class.newInstance)
in all the source.
The remaining warnings are about the deprecation of JApplet, which is another
WHOLE issues entirely.

Modified:
    pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java
    pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java
    pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
    pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java
    pivot/trunk/core/src/org/apache/pivot/util/Service.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java

Modified: pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java (original)
+++ pivot/trunk/charts/src/org/apache/pivot/charts/ChartView.java Tue Sep 11 17:42:52 2018
@@ -16,6 +16,7 @@
  */
 package org.apache.pivot.charts;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.Comparator;
 
 import org.apache.pivot.annotations.UnsupportedOperation;
@@ -332,10 +333,9 @@ public abstract class ChartView extends
             provider.getSkinClass((Class<? extends ChartView>) componentClass);
 
         try {
-            setSkin(skinClass.newInstance());
-        } catch (InstantiationException exception) {
-            throw new IllegalArgumentException(exception);
-        } catch (IllegalAccessException exception) {
+            setSkin(skinClass.getDeclaredConstructor().newInstance());
+        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
+               | InvocationTargetException exception) {
             throw new IllegalArgumentException(exception);
         }
     }

Modified: pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java Tue Sep 11 17:42:52 2018
@@ -933,9 +933,8 @@ public class BXMLSerializer implements S
             Serializer<?> serializer;
             try {
                 serializer = newIncludeSerializer(serializerClass);
-            } catch (InstantiationException exception) {
-                throw new SerializationException(exception);
-            } catch (IllegalAccessException exception) {
+            } catch (InstantiationException | IllegalAccessException
+                   | NoSuchMethodException | InvocationTargetException exception) {
                 throw new SerializationException(exception);
             }
 
@@ -1645,8 +1644,8 @@ public class BXMLSerializer implements S
 
     /**
      * Creates a new serializer to be used on a nested include. The base
-     * implementation simply calls {@code Class.newInstance()}. Subclasses may
-     * override this method to provide an alternate instantiation mechanism,
+     * implementation simply calls {@code Class.getDeclaredConstructor().newInstance()}.
+     * Subclasses may override this method to provide an alternate instantiation mechanism,
      * such as dependency-injected construction.
      *
      * @param type The type of serializer being requested.
@@ -1654,16 +1653,19 @@ public class BXMLSerializer implements S
      * @throws InstantiationException if an object of the given type cannot be instantiated.
      * @throws IllegalAccessException if the class cannot be accessed in the
      * current security environment.
+     * @throws NoSuchMethodException if there is not a no-arg constructor declared in the class.
+     * @throws InvocationTargetException if there was an exception thrown by the constructor.
      */
     protected Serializer<?> newIncludeSerializer(final Class<? extends Serializer<?>> type)
-        throws InstantiationException, IllegalAccessException {
-        return type.newInstance();
+        throws InstantiationException, IllegalAccessException, NoSuchMethodException,
+               InvocationTargetException {
+        return type.getDeclaredConstructor().newInstance();
     }
 
     /**
      * Creates a new typed object as part of the deserialization process. The
-     * base implementation simply calls {@code Class.newInstance()}. Subclasses
-     * may override this method to provide an alternate instantiation mechanism,
+     * base implementation simply calls {@code Class.getDeclaredConstructor().newInstance()}.
+     * Subclasses may override this method to provide an alternate instantiation mechanism,
      * such as dependency-injected construction.
      *
      * @param type The type of object being requested.
@@ -1671,10 +1673,13 @@ public class BXMLSerializer implements S
      * @throws InstantiationException if an object of the given type cannot be instantiated.
      * @throws IllegalAccessException if the class cannot be accessed in the
      * current security environment.
+     * @throws NoSuchMethodException if there is not a no-arg constructor declared in the class.
+     * @throws InvocationTargetException if there was an exception thrown by the constructor.
      */
     protected Object newTypedObject(final Class<?> type)
-        throws InstantiationException, IllegalAccessException {
-        return type.newInstance();
+        throws InstantiationException, IllegalAccessException, NoSuchMethodException,
+               InvocationTargetException {
+        return type.getDeclaredConstructor().newInstance();
     }
 
     /**

Modified: pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/json/JSONSerializer.java Tue Sep 11 17:42:52 2018
@@ -28,6 +28,7 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
@@ -555,8 +556,9 @@ public class JSONSerializer implements S
             }
 
             try {
-                sequence = (Sequence<Object>) sequenceType.newInstance();
-            } catch (InstantiationException | IllegalAccessException exception) {
+                sequence = (Sequence<Object>) sequenceType.getDeclaredConstructor().newInstance();
+            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
+                    | InvocationTargetException exception) {
                 throw new RuntimeException(exception);
             }
         }
@@ -656,8 +658,9 @@ public class JSONSerializer implements S
                 Class<?> beanType = (Class<?>) typeArgument;
 
                 try {
-                    dictionary = new BeanAdapter(beanType.newInstance());
-                } catch (InstantiationException | IllegalAccessException exception) {
+                    dictionary = new BeanAdapter(beanType.getDeclaredConstructor().newInstance());
+                } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
+                        | InvocationTargetException exception) {
                     throw new RuntimeException(exception);
                 }
             } else {
@@ -670,8 +673,9 @@ public class JSONSerializer implements S
                 }
 
                 try {
-                    dictionary = (Dictionary<String, Object>) dictionaryType.newInstance();
-                } catch (InstantiationException | IllegalAccessException exception) {
+                    dictionary = (Dictionary<String, Object>) dictionaryType.getDeclaredConstructor().newInstance();
+                } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
+                        | InvocationTargetException exception) {
                     throw new RuntimeException(exception);
                 }
             }

Modified: pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/serialization/CSVSerializer.java Tue Sep 11 17:42:52 2018
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.nio.charset.Charset;
@@ -289,10 +290,10 @@ public class CSVSerializer implements Se
                 if (itemType instanceof ParameterizedType) {
                     ParameterizedType parameterizedItemType = (ParameterizedType) itemType;
                     Class<?> rawItemType = (Class<?>) parameterizedItemType.getRawType();
-                    item = rawItemType.newInstance();
+                    item = rawItemType.getDeclaredConstructor().newInstance();
                 } else {
                     Class<?> classItemType = (Class<?>) itemType;
-                    item = classItemType.newInstance();
+                    item = classItemType.getDeclaredConstructor().newInstance();
                 }
 
                 if (item instanceof Dictionary<?, ?>) {
@@ -300,9 +301,8 @@ public class CSVSerializer implements Se
                 } else {
                     itemDictionary = new BeanAdapter(item);
                 }
-            } catch (IllegalAccessException exception) {
-                throw new SerializationException(exception);
-            } catch (InstantiationException exception) {
+            } catch (IllegalAccessException | InstantiationException | NoSuchMethodException
+                   | InvocationTargetException exception) {
                 throw new SerializationException(exception);
             }
 

Modified: pivot/trunk/core/src/org/apache/pivot/util/Service.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Service.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Service.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/Service.java Tue Sep 11 17:42:52 2018
@@ -20,6 +20,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
 import java.nio.charset.StandardCharsets;
 
 /**
@@ -100,10 +101,9 @@ public final class Service {
         Object provider = null;
         if (providerClass != null) {
             try {
-                provider = providerClass.newInstance();
-            } catch (InstantiationException exception) {
-                // No-op
-            } catch (IllegalAccessException exception) {
+                provider = providerClass.getDeclaredConstructor().newInstance();
+            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
+                   | InvocationTargetException exception) {
                 // No-op
             }
         }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/BrowserApplicationContext.java Tue Sep 11 17:42:52 2018
@@ -226,7 +226,8 @@ public final class BrowserApplicationCon
                 } else {
                     try {
                         Class<?> applicationClass = Class.forName(applicationClassName);
-                        HostApplet.this.application = (Application) applicationClass.newInstance();
+                        HostApplet.this.application =
+                            (Application) applicationClass.getDeclaredConstructor().newInstance();
                     } catch (Throwable throwable) {
                         throwable.printStackTrace();
                     }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Tue Sep 11 17:42:52 2018
@@ -22,6 +22,7 @@ import java.awt.Graphics2D;
 import java.awt.Rectangle;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
+import java.lang.reflect.InvocationTargetException;
 import java.util.Iterator;
 
 import org.apache.pivot.beans.BeanAdapter;
@@ -576,10 +577,9 @@ public abstract class Component implemen
 
         if (type == componentClass) {
             try {
-                setSkin(skinClass.newInstance());
-            } catch (InstantiationException exception) {
-                throw new IllegalArgumentException(exception);
-            } catch (IllegalAccessException exception) {
+                setSkin(skinClass.getDeclaredConstructor().newInstance());
+            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
+                   | InvocationTargetException exception) {
                 throw new IllegalArgumentException(exception);
             }
         }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java?rev=1840595&r1=1840594&r2=1840595&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/DesktopApplicationContext.java Tue Sep 11 17:42:52 2018
@@ -30,6 +30,7 @@ import java.awt.event.KeyEvent;
 import java.awt.event.WindowEvent;
 import java.awt.image.BufferedImage;
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
 import java.net.URL;
@@ -644,13 +645,10 @@ public final class DesktopApplicationCon
             if (useApplicationInstance) {
                 // application has already been set, before calling this method
             } else {
-                application = (Application) applicationClass.newInstance();
+                application = (Application) applicationClass.getDeclaredConstructor().newInstance();
             }
-        } catch (ClassNotFoundException exception) {
-            exception.printStackTrace();
-        } catch (InstantiationException exception) {
-            exception.printStackTrace();
-        } catch (IllegalAccessException exception) {
+        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
+               | NoSuchMethodException | InvocationTargetException exception) {
             exception.printStackTrace();
         }
 
@@ -725,7 +723,7 @@ public final class DesktopApplicationCon
                     }
                 };
 
-                Object eawtApplication = eawtApplicationClass.newInstance();
+                Object eawtApplication = eawtApplicationClass.getDeclaredConstructor().newInstance();
 
                 setEnabledAboutMenuMethod.invoke(eawtApplication,
                     Boolean.valueOf(application instanceof Application.AboutHandler));