Skip to content

Commit c765a75

Browse files
authored
Merge pull request #25813 from dmatej/referencecleaner
Fixed NPE and noticed NPE in JDK code
2 parents 18abbec + 3ab9a01 commit c765a75

4 files changed

Lines changed: 27 additions & 10 deletions

File tree

appserver/common/container-common/src/main/java/com/sun/enterprise/container/common/impl/managedbean/ManagedBeanManagerImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -418,7 +418,9 @@ public <T> T createManagedBean(ManagedBeanDescriptor managedBeanDescriptor, Clas
418418

419419
// Need to keep track of context in order to destroy properly
420420
Map<Object, CDIInjectionContext> bundleNonManagedObjs = cdiManagedBeanInstanceMap.get(bundleDescriptor);
421-
bundleNonManagedObjs.put(callerObject, cdiContext);
421+
if (bundleNonManagedObjs != null) {
422+
bundleNonManagedObjs.put(callerObject, cdiContext);
423+
}
422424

423425
} else {
424426
JavaEEInterceptorBuilder interceptorBuilder = (JavaEEInterceptorBuilder) managedBeanDescriptor.getInterceptorBuilder();

appserver/tests/tck/embedded_ejb_smoke/runner/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
<version>${project.version}</version>
6060
<scope>test</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>org.glassfish.main</groupId>
64+
<artifactId>glassfish-jul-extension</artifactId>
65+
<scope>test</scope>
66+
</dependency>
6267
<dependency>
6368
<groupId>org.glassfish.main.distributions</groupId>
6469
<artifactId>glassfish</artifactId>

appserver/tests/tck/embedded_ejb_smoke/runner/src/test/java/com/sun/ts/run/EmbeddedRunnerITest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.sun.ts.run;
1717

1818
import com.sun.ts.lib.harness.ExecTSTestCmd;
19+
import com.sun.javatest.Status;
1920

2021
import java.io.IOException;
2122
import java.io.OutputStreamWriter;
@@ -80,13 +81,14 @@ List<String> getJavaOptions() {
8081
"-Djava.util.logging.config.file=" + System.getProperty("glassfish.home") + "/glassfish/domains/domain1/config/logging.properties",
8182
"-Dtest.ejb.stateful.timeout.wait.seconds=180 ",
8283
"-Ddeliverable.class=com.sun.ts.lib.deliverable.cts.CTSDeliverable",
83-
84+
"--module-path", System.getProperty("glassfish.home") + "/glassfish/lib/bootstrap",
85+
"--add-modules", "ALL-MODULE-PATH",
8486
"--add-opens=jdk.management/com.sun.management.internal=ALL-UNNAMED",
8587
"--add-opens=java.base/sun.net.www.protocol.jrt=ALL-UNNAMED",
8688
"--add-opens=java.base/java.lang=ALL-UNNAMED",
8789
"--add-opens=java.base/java.util=ALL-UNNAMED",
8890
"--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED",
89-
"--add-opens=java.naming/javax.naming.spi=ALL-UNNAMED")
91+
"--add-opens=java.naming/javax.naming.spi=org.glassfish.main.jdke")
9092
;
9193

9294
if (System.getProperty("maven.tck.debug") != null && !System.getProperty("maven.tck.debug").isEmpty()) {
@@ -124,10 +126,8 @@ String getClassPath() {
124126

125127
return String.join(":", List.of(
126128
localRepository + "/org/glassfish/main/tests/tck/tsharness/" + glassfishVersion + "/tsharness-" + glassfishVersion + ".jar",
127-
localRepository + "/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar",
128129
System.getProperty("glassfish.home") + "/glassfish/lib/embedded/glassfish-embedded-static-shell.jar",
129130
copiedEjbJar.toString()
130131
));
131132
}
132-
133133
}

appserver/web/war-util/src/main/java/org/glassfish/web/loader/ReferenceCleaner.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation
33
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
44
* Copyright 2004 The Apache Software Foundation
55
*
@@ -134,13 +134,12 @@ private void checkThreadLocalsForLeaks() {
134134
}
135135
final Object threadLocalMap = threadLocalsField.get(thread);
136136
if (threadLocalMap != null) {
137-
expungeStaleEntriesMethod.invoke(threadLocalMap);
137+
expungeStaleEntries(expungeStaleEntriesMethod, threadLocalMap);
138138
checkThreadLocalMapForLeaks(threadLocalMap, tableField);
139139
}
140-
141140
final Object inheritableMap = inheritableThreadLocalsField.get(thread);
142141
if (inheritableMap != null) {
143-
expungeStaleEntriesMethod.invoke(inheritableMap);
142+
expungeStaleEntries(expungeStaleEntriesMethod, inheritableMap);
144143
checkThreadLocalMapForLeaks(inheritableMap, tableField);
145144
}
146145
}
@@ -180,6 +179,17 @@ private Thread[] getThreads() {
180179
}
181180

182181

182+
private void expungeStaleEntries(final Method expungeStaleEntriesMethod, final Object threadLocalMap)
183+
throws ReflectiveOperationException {
184+
try {
185+
expungeStaleEntriesMethod.invoke(threadLocalMap);
186+
} catch (NullPointerException e) {
187+
// tab[staleSlot] can be null in ThreadLocalMap.expungeStaleEntry, seen in test logs
188+
LOG.log(WARNING, "Detected NPE caused by the JDK code, cleanup of thread locals failed.", e);
189+
}
190+
}
191+
192+
183193
/**
184194
* Analyzes the given thread local map object. Also pass in the field that
185195
* points to the internal table to save re-calculating it on every

0 commit comments

Comments
 (0)