Skip to content

Commit

Permalink
Use try-with-resources to close a URLClassLoader.
Browse files Browse the repository at this point in the history
Closes #7301.

RELNOTES=n/a
PiperOrigin-RevId: 651523673
  • Loading branch information
dk2k authored and Google Java Core Libraries committed Jul 11, 2024
1 parent 7e66ec4 commit 8b6d8bb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions guava/src/com/google/common/base/FinalizableReferenceQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,16 @@ static class DecoupledLoader implements FinalizerLoader {
@Override
@CheckForNull
public Class<?> loadFinalizer() {
try {
/*
* We use URLClassLoader because it's the only concrete class loader implementation in the
* JDK. If we used our own ClassLoader subclass, Finalizer would indirectly reference this
* class loader:
*
* Finalizer.class -> CustomClassLoader -> CustomClassLoader.class -> This class loader
*
* System class loader will (and must) be the parent.
*/
ClassLoader finalizerLoader = newLoader(getBaseUrl());
/*
* We use URLClassLoader because it's the only concrete class loader implementation in the
* JDK. If we used our own ClassLoader subclass, Finalizer would indirectly reference this
* class loader:
*
* Finalizer.class -> CustomClassLoader -> CustomClassLoader.class -> This class loader
*
* System class loader will (and must) be the parent.
*/
try (URLClassLoader finalizerLoader = newLoader(getBaseUrl())) {
return finalizerLoader.loadClass(FINALIZER_CLASS_NAME);
} catch (Exception e) {
logger.log(Level.WARNING, LOADING_ERROR, e);
Expand Down

0 comments on commit 8b6d8bb

Please sign in to comment.