Skip to content

Fix InputStream resource leak in CritterGizmoGenerator#4206

Merged
evanchooly merged 2 commits intophase-4-move-critter-corefrom
copilot/sub-pr-4205
Mar 6, 2026
Merged

Fix InputStream resource leak in CritterGizmoGenerator#4206
evanchooly merged 2 commits intophase-4-move-critter-corefrom
copilot/sub-pr-4205

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

getResourceAsStream in CritterGizmoGenerator.generate() returned an InputStream that was never closed, leaking the resource on both happy and exception paths.

Changes

  • Wrapped the InputStream acquisition and ClassReader consumption in a single try-with-resources block, ensuring the stream is closed in all cases
// Before
java.io.InputStream inputStream = type.getClassLoader().getResourceAsStream(resourceName);
if (inputStream == null) {
    throw new IllegalArgumentException(...);
}
try {
    new ClassReader(inputStream).accept(classNode, 0);
} catch (IOException e) { ... }

// After
try (java.io.InputStream inputStream = type.getClassLoader().getResourceAsStream(resourceName)) {
    if (inputStream == null) {
        throw new IllegalArgumentException(...);
    }
    new ClassReader(inputStream).accept(classNode, 0);
} catch (IOException e) { ... }

The null check stays inside the try block — Java's try-with-resources skips close() on null resources (JLS §14.20.3), so no NullPointerException risk.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…izmoGenerator

Co-authored-by: evanchooly <195021+evanchooly@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 6, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • central.sonatype.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591 -Dmaven.mainClass=org.apache.maven.cling.MavenCling -Dlibrary.jline.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/lib/jline-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/morphia/morphia org.codehaus.plexus.classworlds.launcher.Launcher compile -pl core -am -DskipTests (dns block)
  • develocity.commonhaus.dev
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591 -Dmaven.mainClass=org.apache.maven.cling.MavenCling -Dlibrary.jline.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/lib/jline-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/morphia/morphia org.codehaus.plexus.classworlds.launcher.Launcher compile -pl core -am -DskipTests (dns block)
  • repo.eclipse.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591 -Dmaven.mainClass=org.apache.maven.cling.MavenCling -Dlibrary.jline.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/lib/jline-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/morphia/morphia org.codehaus.plexus.classworlds.launcher.Launcher compile -pl core -am -DskipTests (dns block)
  • repository.apache.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591 -Dmaven.mainClass=org.apache.maven.cling.MavenCling -Dlibrary.jline.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/lib/jline-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/morphia/morphia org.codehaus.plexus.classworlds.launcher.Launcher compile -pl core -am -DskipTests (dns block)
  • repository.jboss.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591 -Dmaven.mainClass=org.apache.maven.cling.MavenCling -Dlibrary.jline.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/lib/jline-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/morphia/morphia org.codehaus.plexus.classworlds.launcher.Launcher compile -pl core -am -DskipTests (dns block)
  • repository.ow2.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591 -Dmaven.mainClass=org.apache.maven.cling.MavenCling -Dlibrary.jline.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-4.0.0-rc-5/1d86e591/lib/jline-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/morphia/morphia org.codehaus.plexus.classworlds.launcher.Launcher compile -pl core -am -DskipTests (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Apply feedback from review on moving critter-core into morphia-core Fix InputStream resource leak in CritterGizmoGenerator Mar 6, 2026
@evanchooly evanchooly marked this pull request as ready for review March 6, 2026 18:34
@evanchooly evanchooly merged commit b467944 into phase-4-move-critter-core Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants