This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch release22.01
in repository https://gitbox.apache.org/repos/asf/ofbiz-plugins.git


The following commit(s) were added to refs/heads/release22.01 by this push:
     new f29c84c  Improved: Remove deprecation warning by removing direct call 
to Class::newInstance
f29c84c is described below

commit f29c84c0524431eb14ff44f5f4f968a835a4e6e6
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Fri Apr 1 10:41:55 2022 +0200

    Improved: Remove deprecation warning by removing direct call to 
Class::newInstance
    
    Class.newInstance() has a flaw, in which any Throwable from the constructor 
is
    thrown unchecked. It was deprecated in Java 9, but not marked for removal.
    It shows as a deprecation warning when compiling OfBiz with Java 11.
    
    Thanks: Heinz Kabutz for reporting and initially committing 0e6732b. This
    completes in plugins and all will we backported
---
 .../main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java    | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git 
a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java 
b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java
index 27066aa..5444242 100644
--- a/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java
+++ b/rest-api/src/main/java/org/apache/ofbiz/ws/rs/util/OpenApiUtil.java
@@ -18,6 +18,7 @@
  
*******************************************************************************/
 package org.apache.ofbiz.ws.rs.util;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -298,8 +299,9 @@ public final class OpenApiUtil {
             return null;
         }
         try {
-            schema = (Schema<?>) schemaClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+            schema = (Schema<?>) 
schemaClass.getDeclaredConstructor().newInstance();
+        } catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+                | SecurityException e) {
             e.printStackTrace();
         }
 
@@ -377,8 +379,9 @@ public final class OpenApiUtil {
                 continue;
             }
             try {
-                schema = (Schema<?>) schemaClass.newInstance();
-            } catch (InstantiationException | IllegalAccessException e) {
+                schema = (Schema<?>) 
schemaClass.getDeclaredConstructor().newInstance();
+            } catch (InstantiationException | IllegalAccessException | 
IllegalArgumentException | InvocationTargetException | NoSuchMethodException
+                    | SecurityException e) {
                 e.printStackTrace();
             }
             if (schemaClass != null) {

Reply via email to