Skip to content

Commit

Permalink
Upgrade Weld and ClassFileWriter (helidon-io#7720)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-langer authored and dalexandrov committed Oct 17, 2023
1 parent 8c56894 commit 73beae9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<version.lib.jandex>3.1.2</version.lib.jandex>
<version.lib.jaxb-core>4.0.3</version.lib.jaxb-core>
<version.lib.jaxb-impl>4.0.3</version.lib.jaxb-impl>
<version.lib.jboss.classfilewriter>1.2.5.Final</version.lib.jboss.classfilewriter>
<version.lib.jboss.classfilewriter>1.3.0.Final</version.lib.jboss.classfilewriter>
<version.lib.jboss.logging>3.5.3.Final</version.lib.jboss.logging>
<!-- Force upgrade version used by maven-jaxb2-plugin. Needed to support Java 16 -->
<version.lib.jaxb-runtime>4.0.3</version.lib.jaxb-runtime>
Expand Down Expand Up @@ -152,7 +152,7 @@
<version.lib.typesafe-config>1.4.2</version.lib.typesafe-config>
<version.lib.tyrus>2.0.4</version.lib.tyrus>
<version.lib.weld-api>5.0.SP3</version.lib.weld-api>
<version.lib.weld>5.1.0.Final</version.lib.weld>
<version.lib.weld>5.1.1.SP2</version.lib.weld>
<version.lib.yasson>2.0.4</version.lib.yasson>
<version.lib.zipkin.sender-urlconnection>2.16.4</version.lib.zipkin.sender-urlconnection>
<version.lib.zipkin>2.12.5</version.lib.zipkin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public ProxyFactory(String contextId, Class<?> proxiedBeanType, Set<? extends Ty
static String getProxyName(String contextId, Class<?> proxiedBeanType, Set<? extends Type> typeClosure, Bean<?> bean) {
TypeInfo typeInfo = TypeInfo.of(typeClosure);
final String className;
org.jboss.weld.bean.proxy.ProxyFactory.ProxyNameHolder holder;
ProxyNameHolder holder;
if (typeInfo.getSuperClass() == Object.class) {
// for classes that do not have an enclosing class, we want the super interface to be first
if (proxiedBeanType.getEnclosingClass() == null) {
Expand Down Expand Up @@ -262,7 +262,7 @@ static String getProxyName(String contextId, Class<?> proxiedBeanType, Set<? ext
StringBuilder name = new StringBuilder(typeInfo.getSuperClass().getSimpleName() + "$");
holder = createCompoundProxyName(contextId, bean, typeInfo, name);
} else {
holder = new org.jboss.weld.bean.proxy.ProxyFactory.ProxyNameHolder(null, typeInfo.getSuperClass().getSimpleName(), bean);
holder = new ProxyNameHolder(null, typeInfo.getSuperClass().getSimpleName(), bean);
}
}
className = holder.getClassName() + PROXY_SUFFIX;
Expand Down Expand Up @@ -295,7 +295,7 @@ static String getProxyName(String contextId, Class<?> proxiedBeanType, Set<? ext
/*
* Helidon modification (original method with different body)
*/
private static org.jboss.weld.bean.proxy.ProxyFactory.ProxyNameHolder createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo, StringBuilder name) {
private static ProxyNameHolder createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo, StringBuilder name) {
String className;
String proxyPackage = null;
// we need a sorted collection without repetition, hence LinkedHashSet
Expand Down Expand Up @@ -331,7 +331,7 @@ private static org.jboss.weld.bean.proxy.ProxyFactory.ProxyNameHolder createComp
}
// we use unique names, we should never get a duplicity
className = name.toString();
return new org.jboss.weld.bean.proxy.ProxyFactory.ProxyNameHolder(proxyPackage, className, bean);
return new ProxyNameHolder(proxyPackage, className, bean);
}

private static String getEnclosingPrefix(Class<?> clazz) {
Expand Down Expand Up @@ -619,8 +619,8 @@ private Class<T> createProxyClass(Class<?> originalClass, String proxyClassName)

ProtectionDomain domain = AccessController.doPrivileged(new GetProtectionDomainAction(proxiedBeanType));

if (proxiedBeanType.getPackage() == null || proxiedBeanType.equals(Object.class)) {
domain = org.jboss.weld.bean.proxy.ProxyFactory.class.getProtectionDomain();
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);
Expand All @@ -632,7 +632,10 @@ private Class<T> createProxyClass(Class<?> originalClass, String proxyClassName)

private ClassFile newClassFile(String name, int accessFlags, String superclass, String... interfaces) {
try {
return new ClassFile(name, accessFlags, superclass, interfaces);
// We need to use a (non-deprecated) method that avoids instantiating DefaultClassFactory.INSTANCE
// If that happens, we will have module accessibility issues and the need to use --add-opens clausules
// NOTE: the CL and ClassFactory are never really used to define the class, see WeldDefaultProxyServices
return new ClassFile(name, accessFlags, superclass, ProxyFactory.class.getClassLoader(), DummyClassFactoryImpl.INSTANCE, interfaces);
} catch (Exception e) {
throw BeanLogger.LOG.unableToCreateClassFile(name, e.getCause());
}
Expand Down

0 comments on commit 73beae9

Please sign in to comment.