Skip to content

Commit

Permalink
WELD-2763 : Apply fix for choosing proxy package, copied from weld/pu…
Browse files Browse the repository at this point in the history
  • Loading branch information
alwin-joseph committed Oct 23, 2023
1 parent 52e741f commit 0bd9cf2
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ static String getProxyName(String contextId, Class<?> proxiedBeanType, Set<? ext
}
}
if (typeModified) {
//this bean has interfaces that the base type is not assignable to
//which can happen with some creative use of the SPI
//interface only bean.
// This bean has interfaces that the base type is not assignable to.
// One example of this is an EJB bean using @Local and declaring an interface it doesn't implement.
// Another case is a CDI bean with type added via ProcessBeanAttributes which isn't directly implemented.
StringBuilder name = new StringBuilder(typeInfo.getSuperClass().getSimpleName() + "$");
holder = createCompoundProxyName(contextId, bean, typeInfo, name);
holder = createCompoundProxyName(contextId, bean, typeInfo, name, bean.getBeanClass().getPackage().getName());
} else {
holder = new ProxyNameHolder(null, typeInfo.getSuperClass().getSimpleName(), bean);
}
Expand Down Expand Up @@ -241,14 +241,21 @@ static String getProxyName(String contextId, Class<?> proxiedBeanType, Set<? ext
return proxyPackage + '.' + getEnclosingPrefix(proxiedBeanType) + className;
}

private static ProxyNameHolder createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo, StringBuilder name) {
private static ProxyNameHolder createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo,
StringBuilder name) {
return createCompoundProxyName(contextId, bean, typeInfo, name, null);
}

private static ProxyNameHolder createCompoundProxyName(String contextId, Bean<?> bean, TypeInfo typeInfo,
StringBuilder name, String knownProxyPackage) {
String className;
String proxyPackage = null;
String proxyPackage = knownProxyPackage;
// we need a sorted collection without repetition, hence LinkedHashSet
final Set<String> interfaces = new LinkedHashSet<>();
// for producers, try to determine the most specific class and make sure the proxy starts with the same package and class
if (bean != null && bean instanceof AbstractProducerBean) {
Class<?> mostSpecificClass = ((AbstractProducerBean) bean).getType();
// for producers, always override the proxy package
proxyPackage = mostSpecificClass.getPackage().getName();
if (mostSpecificClass.getDeclaringClass() != null) {
interfaces.add(mostSpecificClass.getDeclaringClass().getSimpleName());
Expand Down

0 comments on commit 0bd9cf2

Please sign in to comment.