You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2020/06/03 08:43:43 UTC

[openwebbeans] branch master updated: [OWB-1214] fallback on loadClass(package-info) when getPackage is not available in the JVM

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

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 5d00bcc  [OWB-1214] fallback on loadClass(package-info) when getPackage is not available in the JVM
5d00bcc is described below

commit 5d00bcc5c9d9a5efc0a9848d46eff91ef5186025
Author: Romain Manni-Bucau <rm...@gmail.com>
AuthorDate: Wed Jun 3 10:43:26 2020 +0200

    [OWB-1214] fallback on loadClass(package-info) when getPackage is not available in the JVM
---
 .../org/apache/webbeans/config/BeansDeployer.java  | 55 ++++++++++------------
 1 file changed, 25 insertions(+), 30 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
index 99689fa..057db3d 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
@@ -145,30 +145,6 @@ public class BeansDeployer
     private static final Logger logger = WebBeansLoggerFacade.getLogger(BeansDeployer.class);
     public static final String JAVAX_ENTERPRISE_PACKAGE = "javax.enterprise.";
 
-    private static final Method GET_PACKAGE;
-    static
-    {
-        Method getPackage;
-        try
-        {
-            getPackage = ClassLoader.class.getDeclaredMethod("getDefinedPackage", String.class);
-            getPackage.setAccessible(true);
-        }
-        catch (NoSuchMethodException e)
-        {
-            try
-            {
-                getPackage = ClassLoader.class.getDeclaredMethod("getPackage", String.class);
-                getPackage.setAccessible(true);
-            }
-            catch (NoSuchMethodException ex)
-            {
-                throw new IllegalStateException(ex);
-            }
-        }
-        GET_PACKAGE = getPackage;
-    }
-
 
     /**Deployment is started or not*/
     protected boolean deployed;
@@ -1443,13 +1419,32 @@ public class BeansDeployer
                 {
                     return result;
                 }
-                try // this is related to classloader and not to Package actually :( so we need reflection
+                while (true)
                 {
-                    pckge = Package.class.cast(GET_PACKAGE.invoke(classLoader, previousPackage));
-                }
-                catch (Exception e)
-                {
-                    throw new IllegalStateException(e);
+                    try // not always existing but enables to go further when getPackage is not available (graal)
+                    {
+                        pckge = classLoader.loadClass(previousPackage +
+                                (previousPackage.isEmpty() ? "" :".") + "package-info").getPackage();
+                        break;
+                    }
+                    catch (Exception e)
+                    {
+                        if (previousPackage.isEmpty())
+                        {
+                            pckge = null;
+                            break;
+                        }
+                        packageVetoCache.put(previousPackage, false);
+                        idx = previousPackage.lastIndexOf('.');
+                        if (idx > 0)
+                        {
+                            previousPackage = previousPackage.substring(0, idx);
+                        }
+                        else
+                        {
+                            previousPackage = "";
+                        }
+                    }
                 }
             }
             else