diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SnifferManagerImpl.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SnifferManagerImpl.java index a413984e215..1889421068f 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SnifferManagerImpl.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/SnifferManagerImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2020-2021] Payara Foundation and/or affiliates +// Portions Copyright 2020-2024 Payara Foundation and/or affiliates package com.sun.enterprise.v3.server; @@ -156,47 +156,47 @@ public Collection getSniffers(DeploymentContext context, List uris private List getApplicableSniffers(DeploymentContext context, List uris, Types types, Collection sniffers, boolean checkPath) { ArchiveType archiveType = habitat.getService(ArchiveType.class, context.getArchiveHandler().getArchiveType()); - if (sniffers==null || sniffers.isEmpty()) { + if (sniffers == null || sniffers.isEmpty()) { return Collections.emptyList(); } List result = new ArrayList(); for (T sniffer : sniffers) { - if (archiveType != null && - !sniffer.supportsArchiveType(archiveType)) { + if (archiveType != null && !sniffer.supportsArchiveType(archiveType)) { continue; } String[] annotationNames = sniffer.getAnnotationNames(context); - if (annotationNames==null) continue; - for (String annotationName : annotationNames) { - if (types != null) { - Type type = types.getBy(annotationName); - if (type instanceof AnnotationType) { - Collection elements = ((AnnotationType) type).allAnnotatedTypes(); - for (AnnotatedElement element : elements) { - if (checkPath) { - Type t; - if (element instanceof Member) { - t = ((Member) element).getDeclaringType(); - } else if (element instanceof Type) { - t = (Type) element; - } else if (element instanceof ParameterizedType) { - t = ((ParameterizedType) element).getType(); - } else { - LOGGER.log(Level.WARNING, "Unrecognised type: {0}.", element); - continue; - } - if (t.wasDefinedIn(uris)) { - result.add(sniffer); - break; + if (annotationNames == null || types == null) { + continue; + } + for (String annotationName : annotationNames) { + types.getAllTypes().stream() + .filter(type -> type instanceof AnnotationType && type.getName().equals(annotationName)) + .findFirst().ifPresent(type -> { + Collection elements = ((AnnotationType) type).allAnnotatedTypes(); + for (AnnotatedElement element : elements) { + if (checkPath) { + Type t; + if (element instanceof Member) { + t = ((Member) element).getDeclaringType(); + } else if (element instanceof Type) { + t = (Type) element; + } else if (element instanceof ParameterizedType) { + t = ((ParameterizedType) element).getType(); + } else { + LOGGER.log(Level.WARNING, "Unrecognised type: {0}.", element); + continue; + } + if (t.wasDefinedIn(uris)) { + result.add(sniffer); + break; + } + } else { + result.add(sniffer); + break; + } } - } else { - result.add(sniffer); - break; - } - } - } - } + }); } } return result;