Skip to content

Commit

Permalink
2.x Upgrade Weld #6575 (#6805)
Browse files Browse the repository at this point in the history
* 2.x Upgrade Weld #6575

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>

* Rework ProxyFactory

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>

---------

Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos authored May 19, 2023
1 parent 9f5f4db commit 7c4ecc3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nb-configuration.xml
.settings/
.project
.classpath
.factorypath

# Asciidoctor
.asciidoctor/
Expand Down
4 changes: 2 additions & 2 deletions dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
<version.lib.tyrus>1.17</version.lib.tyrus>
<version.lib.validation-api>2.0.2</version.lib.validation-api>
<version.lib.websockets-api>1.1.2</version.lib.websockets-api>
<version.lib.weld-api>3.1.SP2</version.lib.weld-api>
<version.lib.weld>3.1.6.Final</version.lib.weld>
<version.lib.weld-api>3.1.SP4</version.lib.weld-api>
<version.lib.weld>3.1.9.Final</version.lib.weld>
<version.lib.yasson>1.0.11</version.lib.yasson>
<version.lib.zipkin.sender-urlconnection>2.12.0</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
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -600,18 +599,13 @@ private Class<T> 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<T> proxyClass;
if (classLoader == null) {
proxyClass = cast(ClassFileUtils.toClass(proxyClassType, originalClass, proxyServices, domain));
} else {
proxyClass = cast(ClassFileUtils.toClass(proxyClassType, classLoader, domain));
}
Class<T> proxyClass = cast(toClass(proxyClassType, originalClass, proxyServices, domain));
BeanLogger.LOG.createdProxyClass(proxyClass, Arrays.toString(proxyClass.getInterfaces()));
return proxyClass;
}
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 7c4ecc3

Please sign in to comment.