[openwebbeans] branch master updated: [OWB-1376] fix unsafe usage to define classes

2021-03-13 Thread rmannibucau
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 8ee9f5f  [OWB-1376] fix unsafe usage to define classes
8ee9f5f is described below

commit 8ee9f5fb288131444aeb880fad24cc99f86a9091
Author: Romain Manni-Bucau 
AuthorDate: Sat Mar 13 21:04:32 2021 +0100

[OWB-1376] fix unsafe usage to define classes
---
 .../java/org/apache/webbeans/proxy/Unsafe.java | 31 ++
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Unsafe.java 
b/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Unsafe.java
index 2085883..9beb112 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Unsafe.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/proxy/Unsafe.java
@@ -26,6 +26,7 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
 import org.apache.webbeans.exception.ProxyGenerationException;
@@ -38,8 +39,8 @@ public class Unsafe
  * We use it for creating the proxy instance without fully
  * initializing the class.
  */
-private Object unsafe;
-private Object internalUnsafe;
+private final Object unsafe;
+private final Object internalUnsafe;
 private Method unsafeAllocateInstance;
 private final AtomicReference unsafeDefineClass = new 
AtomicReference<>();
 
@@ -66,7 +67,7 @@ public class Unsafe
 {
 final Field theInternalUnsafe = 
unsafeClass.getDeclaredField("theInternalUnsafe");
 theInternalUnsafe.setAccessible(true);
-return theInternalUnsafe.get(null).getClass();
+return theInternalUnsafe.get(null);
 }
 catch (final Exception notJ11OrMore)
 {
@@ -172,7 +173,7 @@ public class Unsafe
 else
 {
 
-definedClass = (Class) unsafeDefineClass().invoke(unsafe, 
proxyName, proxyBytes, 0, proxyBytes.length, classLoader, null);
+definedClass = (Class) 
unsafeDefineClass().invoke(internalUnsafe, proxyName, proxyBytes, 0, 
proxyBytes.length, classLoader, null);
 }
 
 return (Class) Class.forName(definedClass.getName(), true, 
classLoader);
@@ -190,7 +191,10 @@ public class Unsafe
 // default error handling
 }
 }
-throw new ProxyGenerationException(le.getCause());
+throw new ProxyGenerationException(
+le.getMessage() + (isJava16OrMore() ? "\n" +
+"On Java 16 ensure to set --add-exports 
java.base/jdk.internal.misc=ALL-UNNAMED on the JVM" : ""),
+le.getCause());
 }
 catch (Throwable e)
 {
@@ -198,6 +202,23 @@ public class Unsafe
 }
 }
 
+private boolean isJava16OrMore()
+{
+final String version = System.getProperty("java.version", "-1");
+final int end = IntStream.of(version.indexOf('-'), 
version.indexOf('.'))
+.filter(i -> i > 0)
+.min()
+.orElseGet(version::length);
+try
+{
+return Integer.parseInt(version.substring(0, end)) >= 16;
+}
+catch (final NumberFormatException nfe)
+{
+return false;
+}
+}
+
 private Method unsafeDefineClass()
 {
 Method value = unsafeDefineClass.get();



[openwebbeans] branch master updated: trying to unify the logic in fixPreservedPackages to isolate the prefixes we handles in a single 'array like' structure

2021-03-13 Thread rmannibucau
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 044b088  trying to unify the logic in fixPreservedPackages to isolate 
the prefixes we handles in a single 'array like' structure
044b088 is described below

commit 044b088d6270c66b338e0f951b00c37e24e39a2d
Author: Romain Manni-Bucau 
AuthorDate: Sat Mar 13 19:45:56 2021 +0100

trying to unify the logic in fixPreservedPackages to isolate the prefixes 
we handles in a single 'array like' structure
---
 .../org/apache/webbeans/proxy/AbstractProxyFactory.java| 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
 
b/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
index 1b156cf..f66d03b 100644
--- 
a/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
+++ 
b/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
@@ -269,15 +269,15 @@ public abstract class AbstractProxyFactory
 return "org.apache.webbeans.custom.signed." + classToProxy.getName();
 }
 
-protected String fixPreservedPackages(String proxyClassName)
+protected String fixPreservedPackages(final String proxyClassName)
 {
-proxyClassName = fixPreservedPackage(proxyClassName, "java.");
-proxyClassName = fixPreservedPackage(proxyClassName, "javax.");
-proxyClassName = fixPreservedPackage(proxyClassName, "jakarta.");
-proxyClassName = fixPreservedPackage(proxyClassName, "sun.misc.");
-
-return proxyClassName;
+return Stream.of("java.", "javax.", "jakarta.", "sun.misc.")
+.filter(proxyClassName::startsWith)
+.findFirst() // can only be one, you can't start with 2 of them
+.map(it -> fixPreservedPackage(proxyClassName, it))
+.orElse(proxyClassName);
 }
+
 /**
  * Detect if the provided className is in the forbidden package.
  * If so, move it to org.apache.webbeans.custom.



svn commit: r1072314 - in /websites: production/openwebbeans/content/index.html staging/openwebbeans/trunk/content/index.html

2021-03-13 Thread buildbot
Author: buildbot
Date: Sat Mar 13 10:35:07 2021
New Revision: 1072314

Log:
Dynamic update by buildbot for openwebbeans

Modified:
websites/production/openwebbeans/content/index.html
websites/staging/openwebbeans/trunk/content/index.html

Modified: websites/production/openwebbeans/content/index.html
==
(empty)

Modified: websites/staging/openwebbeans/trunk/content/index.html
==
(empty)