Skip to content

Commit

Permalink
Merge pull request #13399 from gaol/WFLY-13647
Browse files Browse the repository at this point in the history
[WFLY-13647] Annotation processing error sun.reflect.annotation.TypeNotPresentExceptionProxy does not indicate issue
  • Loading branch information
jamezp committed Jul 24, 2020
2 parents e2df4ca + 13cb591 commit 1044ec2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
Expand Up @@ -153,7 +153,14 @@ private void processViewAnnotations(final DeploymentUnit deploymentUnit, final C
}

private Collection<Class<?>> getRemoteBusinessInterfaces(final DeploymentUnit deploymentUnit, final Class<?> sessionBeanClass) throws DeploymentUnitProcessingException {
final Remote remoteViewAnnotation = sessionBeanClass.getAnnotation(Remote.class);
final Remote remoteViewAnnotation;
try {
remoteViewAnnotation = sessionBeanClass.getAnnotation(Remote.class);
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw EjbLogger.ROOT_LOGGER.missingClassInAnnotation(Remote.class.getSimpleName(), sessionBeanClass.getName());
}
if (remoteViewAnnotation == null) {
Collection<Class<?>> interfaces = getBusinessInterfacesFromInterfaceAnnotations(sessionBeanClass, Remote.class);
if (!interfaces.isEmpty()) {
Expand All @@ -175,7 +182,14 @@ private Collection<Class<?>> getRemoteBusinessInterfaces(final DeploymentUnit de
}

private Collection<Class<?>> getLocalBusinessInterfaces(final DeploymentUnit deploymentUnit, final Class<?> sessionBeanClass) throws DeploymentUnitProcessingException {
final Local localViewAnnotation = sessionBeanClass.getAnnotation(Local.class);
final Local localViewAnnotation;
try {
localViewAnnotation = sessionBeanClass.getAnnotation(Local.class);
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw EjbLogger.ROOT_LOGGER.missingClassInAnnotation(Local.class.getSimpleName(), sessionBeanClass.getName());
}
if (localViewAnnotation == null) {
Collection<Class<?>> interfaces = getBusinessInterfacesFromInterfaceAnnotations(sessionBeanClass, Local.class);
if (!interfaces.isEmpty()) {
Expand All @@ -197,12 +211,18 @@ private Collection<Class<?>> getLocalBusinessInterfaces(final DeploymentUnit dep
return Arrays.asList(localViews);
}

private static Collection<Class<?>> getBusinessInterfacesFromInterfaceAnnotations(Class<?> sessionBeanClass, Class<? extends Annotation> annotation) {
private static Collection<Class<?>> getBusinessInterfacesFromInterfaceAnnotations(Class<?> sessionBeanClass, Class<? extends Annotation> annotation) throws DeploymentUnitProcessingException {
final Set<Class<?>> potentialBusinessInterfaces = getPotentialBusinessInterfaces(sessionBeanClass);
final Set<Class<?>> businessInterfaces = new HashSet<Class<?>>();
for (Class<?> iface : potentialBusinessInterfaces) {
if (iface.getAnnotation(annotation) != null) {
businessInterfaces.add(iface);
try {
if (iface.getAnnotation(annotation) != null) {
businessInterfaces.add(iface);
}
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw EjbLogger.ROOT_LOGGER.missingClassInAnnotation(annotation.getSimpleName(), iface.getName());
}
}
return businessInterfaces;
Expand Down
3 changes: 3 additions & 0 deletions ejb3/src/main/java/org/jboss/as/ejb3/logging/EjbLogger.java
Expand Up @@ -3222,4 +3222,7 @@ public interface EjbLogger extends BasicLogger {

@Message(id = 520, value = "Legacy host does not support multiple values for attributes: %s")
String multipleValuesNotSupported(Set<String> attributes);

@Message(id = 521, value = "Some classes referenced by annotation: %s in class: %s are missing.")
DeploymentUnitProcessingException missingClassInAnnotation(String anCls, String resCls);
}
Expand Up @@ -148,20 +148,26 @@ public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentU
// Process HandlesTypes for ServletContainerInitializer
Map<Class<?>, Set<ServletContainerInitializer>> typesMap = new HashMap<Class<?>, Set<ServletContainerInitializer>>();
for (ServletContainerInitializer service : scis) {
if (service.getClass().isAnnotationPresent(HandlesTypes.class)) {
HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
Class<?>[] typesArray = handlesTypesAnnotation.value();
if (typesArray != null) {
for (Class<?> type : typesArray) {
Set<ServletContainerInitializer> servicesSet = typesMap.get(type);
if (servicesSet == null) {
servicesSet = new HashSet<ServletContainerInitializer>();
typesMap.put(type, servicesSet);
try {
if (service.getClass().isAnnotationPresent(HandlesTypes.class)) {
HandlesTypes handlesTypesAnnotation = service.getClass().getAnnotation(HandlesTypes.class);
Class<?>[] typesArray = handlesTypesAnnotation.value();
if (typesArray != null) {
for (Class<?> type : typesArray) {
Set<ServletContainerInitializer> servicesSet = typesMap.get(type);
if (servicesSet == null) {
servicesSet = new HashSet<ServletContainerInitializer>();
typesMap.put(type, servicesSet);
}
servicesSet.add(service);
handlesTypes.put(service, new HashSet<Class<?>>());
}
servicesSet.add(service);
handlesTypes.put(service, new HashSet<Class<?>>());
}
}
} catch (ArrayStoreException e) {
// https://bugs.openjdk.java.net/browse/JDK-7183985
// Class.findAnnotation() has a bug under JDK < 11 which throws ArrayStoreException
throw UndertowLogger.ROOT_LOGGER.missingClassInAnnotation(HandlesTypes.class.getSimpleName(), service.getClass().getName());
}
}
Class<?>[] typesArray = typesMap.keySet().toArray(new Class<?>[0]);
Expand Down
Expand Up @@ -416,4 +416,7 @@ public interface UndertowLogger extends BasicLogger {

@Message(id = 103, value = "The time zone id %s is invalid.")
OperationFailedException invalidTimeZoneId(String zoneId);

@Message(id = 104, value = "Some classes referenced by annotation: %s in class: %s are missing.")
DeploymentUnitProcessingException missingClassInAnnotation(String anCls, String resCls);
}

0 comments on commit 1044ec2

Please sign in to comment.