From 7c4ecc3756b46a4ca621f4a69b10d315b4b0b2f3 Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Fri, 19 May 2023 19:01:44 +0200 Subject: [PATCH] 2.x Upgrade Weld #6575 (#6805) * 2.x Upgrade Weld #6575 Signed-off-by: Jorge Bescos Gascon * Rework ProxyFactory Signed-off-by: Jorge Bescos Gascon --------- Signed-off-by: Jorge Bescos Gascon --- .gitignore | 1 + dependencies/pom.xml | 4 +-- .../extension/WeldSubstitutions.java | 12 +------ .../jboss/weld/bean/proxy/ProxyFactory.java | 32 +++++++++++++------ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index fa9986b565f..959b76e0a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ nb-configuration.xml .settings/ .project .classpath +.factorypath # Asciidoctor .asciidoctor/ diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 1d8f5561149..25979c5a83b 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -144,8 +144,8 @@ 1.17 2.0.2 1.1.2 - 3.1.SP2 - 3.1.6.Final + 3.1.SP4 + 3.1.9.Final 1.0.11 2.12.0 2.12.5 diff --git a/integrations/graal/mp-native-image-extension/src/main/java/io/helidon/integrations/graal/mp/nativeimage/extension/WeldSubstitutions.java b/integrations/graal/mp-native-image-extension/src/main/java/io/helidon/integrations/graal/mp/nativeimage/extension/WeldSubstitutions.java index 87b3ecacd3c..710fca5c71a 100644 --- a/integrations/graal/mp-native-image-extension/src/main/java/io/helidon/integrations/graal/mp/nativeimage/extension/WeldSubstitutions.java +++ b/integrations/graal/mp-native-image-extension/src/main/java/io/helidon/integrations/graal/mp/nativeimage/extension/WeldSubstitutions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package io.helidon.integrations.graal.mp.nativeimage.extension; import java.lang.reflect.Type; -import java.security.ProtectionDomain; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; @@ -27,7 +26,6 @@ import com.oracle.svm.core.annotate.RecomputeFieldValue; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; -import org.jboss.classfilewriter.ClassFile; import org.jboss.weld.event.ObserverNotifier; import org.jboss.weld.executor.DaemonThreadFactory; import org.jboss.weld.util.reflection.ParameterizedTypeImpl; @@ -94,12 +92,4 @@ public static void set(Object object, Executor executor) { } } - - @TargetClass(className = "org.jboss.weld.util.bytecode.ClassFileUtils") - static final class ClassFileUtils { - @Substitute - public static Class toClass(ClassFile ct, ClassLoader loader, ProtectionDomain domain) { - throw new IllegalStateException("Cannot load " + ct.getName()); - } - } } diff --git a/microprofile/weld/weld-core-impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java b/microprofile/weld/weld-core-impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java index 1afecbbfe29..cc0f183fb5d 100644 --- a/microprofile/weld/weld-core-impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java +++ b/microprofile/weld/weld-core-impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java @@ -64,7 +64,6 @@ import org.jboss.weld.util.Proxies; import org.jboss.weld.util.Proxies.TypeInfo; import org.jboss.weld.util.bytecode.BytecodeUtils; -import org.jboss.weld.util.bytecode.ClassFileUtils; import org.jboss.weld.util.bytecode.ConstructorUtils; import org.jboss.weld.util.bytecode.DeferredBytecode; import org.jboss.weld.util.bytecode.MethodInformation; @@ -94,7 +93,7 @@ * * Helidon changes are under the copyright of: * - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -600,18 +599,13 @@ private Class createProxyClass(Class originalClass, String proxyClassName) ProtectionDomain domain = AccessController.doPrivileged(new GetProtectionDomainAction(proxiedBeanType)); - if (proxiedBeanType.getPackage() == null || proxiedBeanType.equals(Object.class)) { + if (proxiedBeanType.getPackage() == null || proxiedBeanType.getPackage().getName().isEmpty() || proxiedBeanType.equals(Object.class)) { domain = ProxyFactory.class.getProtectionDomain(); } else if (System.getSecurityManager() != null) { ProtectionDomainCache cache = Container.instance(contextId).services().get(ProtectionDomainCache.class); domain = cache.getProtectionDomainForProxy(domain); } - Class proxyClass; - if (classLoader == null) { - proxyClass = cast(ClassFileUtils.toClass(proxyClassType, originalClass, proxyServices, domain)); - } else { - proxyClass = cast(ClassFileUtils.toClass(proxyClassType, classLoader, domain)); - } + Class proxyClass = cast(toClass(proxyClassType, originalClass, proxyServices, domain)); BeanLogger.LOG.createdProxyClass(proxyClass, Arrays.toString(proxyClass.getInterfaces())); return proxyClass; } @@ -1074,4 +1068,24 @@ private static String getDefaultPackageReason(Class clazz) { } return null; } + + /** + * Delegates proxy creation via {@link ProxyServices} to the integrator or to our own implementation. + */ + protected Class toClass(ClassFile ct, Class originalClass, ProxyServices proxyServices, ProtectionDomain domain) { + try { + byte[] bytecode = ct.toBytecode(); + Class result; + if (domain == null) { + result = proxyServices.defineClass(originalClass, ct.getName(), bytecode, 0, bytecode.length); + } else { + result = proxyServices.defineClass(originalClass, ct.getName(), bytecode, 0, bytecode.length, domain); + } + return result; + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } }