Skip to content

Commit

Permalink
Ignore classes defined in the unnamed pckg inside BeanArchives.index
Browse files Browse the repository at this point in the history
fixes: #26524
  • Loading branch information
michalvavrik committed Jul 12, 2022
1 parent a16ffa8 commit 97571f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Pattern;
import javax.enterprise.context.BeforeDestroyed;
import javax.enterprise.context.Destroyed;
import javax.enterprise.context.Initialized;
Expand All @@ -43,6 +44,8 @@ public final class BeanArchives {

private static final Logger LOGGER = Logger.getLogger(BeanArchives.class);

private static final Pattern MISSING_PACKAGE_PATTERN = Pattern.compile("[^.]+");

/**
*
* @param applicationIndexes
Expand Down Expand Up @@ -279,6 +282,10 @@ static boolean index(Indexer indexer, String className, ClassLoader classLoader)
// Ignore primitives and arrays
return false;
}
if (isInUnnamedPackage(className)) {
LOGGER.debugf("Class %s is defined in the unnamed package that is not indexed", className);
return false;
}
try (InputStream stream = classLoader
.getResourceAsStream(className.replace('.', '/') + ".class")) {
if (stream != null) {
Expand All @@ -292,4 +299,8 @@ static boolean index(Indexer indexer, String className, ClassLoader classLoader)
}
return result;
}

private static boolean isInUnnamedPackage(String className) {
return MISSING_PACKAGE_PATTERN.matcher(className).matches();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.arc.processor;

import org.jboss.jandex.Indexer;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class BeanArchivesTest {

@Test
public void testIndex() {
final Indexer indexer = new Indexer();
Assertions.assertFalse(BeanArchives.index(indexer, "String"));
Assertions.assertTrue(BeanArchives.index(indexer, String.class.getName()));
}

}

0 comments on commit 97571f9

Please sign in to comment.