Skip to content

fix: resource leaks, Zip Slip, process deadlock, and several medium-severity bugs - #276

Merged
mercyblitz merged 10 commits into
mainfrom
copilot/review-code
May 26, 2026
Merged

fix: resource leaks, Zip Slip, process deadlock, and several medium-severity bugs#276
mercyblitz merged 10 commits into
mainfrom
copilot/review-code

Conversation

Copilot AI commented May 25, 2026

Copy link
Copy Markdown
Contributor
  • Replace inputStream.readAllBytes() with IOUtils.toByteArray(inputStream)
  • Replace new ByteArrayInputStream(...) with new FastByteArrayInputStream(...)
  • Update imports accordingly

…eamArtifactResourceResolver

Agent-Logs-Url: https://github.com/microsphere-projects/microsphere-java/sessions/10a7a5c5-6aee-457c-ae4d-dfde02082f85

Co-authored-by: mercyblitz <533114+mercyblitz@users.noreply.github.com>
Copilot AI requested a review from mercyblitz May 25, 2026 12:33
Replace stream-based existence check with a non-IO check using FileObject.getLastModified(). Removes unused IOException import and avoids opening an InputStream (and related exception handling) to determine whether a resource exists, reducing I/O overhead.
@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.52055% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rc/main/java/io/microsphere/util/jar/JarUtils.java 91.66% 1 Missing and 2 partials ⚠️
...g/model/util/ResolvableAnnotationValueVisitor.java 0.00% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ Complexity Δ
...e/classloading/StreamArtifactResourceResolver.java 100.00% <100.00%> (ø) 20.00 <3.00> (ø)
...ore/src/main/java/io/microsphere/net/URLUtils.java 98.73% <100.00%> (+<0.01%) 131.00 <0.00> (ø)
...n/java/io/microsphere/process/ProcessExecutor.java 100.00% <100.00%> (ø) 10.00 <3.00> (-1.00)
.../src/main/java/io/microsphere/util/ClassUtils.java 100.00% <100.00%> (ø) 158.00 <0.00> (ø)
...va/io/microsphere/jdk/tools/compiler/Compiler.java 100.00% <100.00%> (ø) 39.00 <0.00> (ø)
...g/model/util/ResolvableAnnotationValueVisitor.java 97.87% <0.00%> (-2.13%) 24.00 <0.00> (ø)
...rc/main/java/io/microsphere/util/jar/JarUtils.java 96.19% <91.66%> (-3.81%) 37.00 <12.00> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Replace try-with-resources around toJarFile(url) with an explicit try/finally that calls IOUtils.close(jarFile). Add IOUtils and Objects.nonNull imports and remove the now-unused IOException import. This simplifies resource cleanup, delegates close/error handling to IOUtils, and keeps the null check explicit when determining if a file URL refers to a JarFile.
Refactor JarUtils: import IOUtils and use IOUtils.close to close JarFile in a finally block instead of try-with-resources when resolving a JarEntry, and use the SeparatorConstants.FILE_SEPARATOR constant when building target canonical paths. These changes standardize resource cleanup and separator usage across the codebase and add the necessary imports.
Replace the local variable name jarFile_ with jf in ClassUtils.java when opening the JarFile and passing it to INSTANCE.scan. This is a small refactor to simplify the local variable name and improve readability without changing behavior.
Replace the manual null-check and IllegalStateException throw with a call to io.microsphere.util.Assert.assertNotNull and add its static import. This simplifies the constructor by centralizing null validation while preserving the original error message about requiring a JDK.
Remove the unused import of io.microsphere.io.IOUtils from JarUtils.java to clean up code and eliminate a compiler/IDE warning. No functional changes were made.
Fix JarUtils logger reference and improve null-safety and diagnostics: import and use assertNotNull, add @Nonnull/@nullable annotations, document thrown NullPointerException, and add parameter null checks in extract/doExtract. Resolve and log invalid JAR/entry cases (guarded warn logs) and tidy minor formatting/comments. Update tests: expand LoggingTest value source and extend JarUtilsTest with cases for extraction success, null arguments, missing JAR file, and missing JAR entry.
@sonarqubecloud

Copy link
Copy Markdown

@mercyblitz
mercyblitz merged commit 43f5e96 into main May 26, 2026
6 of 7 checks passed
@mercyblitz
mercyblitz deleted the copilot/review-code branch May 26, 2026 02:28
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