Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/src/main/java/javax/jdo/JDOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@
continue;
}
// else assume first line of text is the PMF class name
String[] tokens = line.split("\\s");

Check warning on line 751 in api/src/main/java/javax/jdo/JDOHelper.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this regular expression to a Pattern compiled outside the loop.

See more on https://sonarcloud.io/project/issues?id=db-jdo&issues=AaCWahHMY9lWA-gfKOMX&open=AaCWahHMY9lWA-gfKOMX&pullRequest=140
String pmfClassName = tokens[0];
int indexOfComment = pmfClassName.indexOf("#");
if (indexOfComment == -1) {
Expand Down Expand Up @@ -1579,7 +1579,11 @@
int numberOfJDOEnhancers = 0;
Enumeration<URL> urls = null;
try {
urls = getResources(loader, Constants.SERVICE_LOOKUP_ENHANCER_RESOURCE_NAME);
// Use ctrLoader (falls back to the context class loader when the caller
// passed null) for the service-resource lookup, matching the class
// loading below; passing the original loader made getEnhancer(null)
// always fail with an NPE inside the resource lookup.
urls = getResources(ctrLoader, Constants.SERVICE_LOOKUP_ENHANCER_RESOURCE_NAME);
} catch (Exception ex) {
exceptions.add(ex);
}
Expand Down
16 changes: 16 additions & 0 deletions api/src/test/java/javax/jdo/JDOHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,20 @@ public static PersistenceManagerFactory getPersistenceManagerFactory(Map<?, ?> p
return null;
}
}

/**
* Test that getEnhancer(null) falls back to the thread context class loader for the
* META-INF/services resource lookup as well as for the class loading. Previously the resource
* lookup used the original null loader, so getEnhancer(null) always threw JDOFatalUserException
* ("no enhancer available") even though a TCCL-visible enhancer exists.
*/
@Test
void testGetEnhancerNullLoaderUsesContextClassLoader() {
JDOEnhancer enhancer = JDOHelper.getEnhancer(null);
Assertions.assertNotNull(enhancer, "getEnhancer(null) returned null");
Assertions.assertEquals(
MockEnhancer.class,
enhancer.getClass(),
"getEnhancer(null) did not load the enhancer visible to the context class loader");
}
}
Loading