Skip to content

Fix get-source empty body for Java symbols (Int.MaxValue overflow)#62

Merged
rochala merged 2 commits intomainfrom
worktree-issue-56
Apr 23, 2026
Merged

Fix get-source empty body for Java symbols (Int.MaxValue overflow)#62
rochala merged 2 commits intomainfrom
worktree-issue-56

Conversation

@rochala
Copy link
Copy Markdown
Contributor

@rochala rochala commented Apr 22, 2026

Fixes #57.

Summary

  • SourceFetcher.extractLines did allLines.slice(startLine, endLine + 1) where endLine is Int.MaxValue for Java symbols (no TASTy position). Adding 1 overflows to Int.MinValue, so slice(0, Int.MinValue) returns an empty sequence.
  • Fixed by using allLines.drop(startLine) when endLine == Int.MaxValue.
  • Strengthened the existing integration test to assert that actual source content appears in the output, not just the code fence header.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes get-source returning an empty body for Java symbols by avoiding Int.MaxValue + 1 overflow when extracting source lines from a sources JAR, and updates the integration test intended to guard against regression.

Changes:

  • Update SourceFetcher.extractLines to use drop(startLine) when endLine == Int.MaxValue (Java sentinel).
  • Strengthen the Java get-source integration test assertions to check for expected output content.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/src/cellar/SourceFetcher.scala Prevents empty extraction for Java symbols by avoiding overflow in end index calculation.
lib/test/src/cellar/IntegrationTest.scala Updates get-source integration test to assert Java source output is present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

assert(console.outBuf.toString.contains("```java"), s"Output: ${console.outBuf}")
val out = console.outBuf.toString
assert(out.contains("```java"), s"Output: $out")
assert(out.contains("CellarJavaClass"), s"Expected source body in: $out")
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new assertion out.contains("CellarJavaClass") doesn’t actually prove the source body is present, because the header line prints the entry path (e.g. .../CellarJavaClass.java), so the class name will be present even when the body is empty (the original bug case). Consider asserting on a snippet that can only come from the file contents (e.g. public class CellarJavaClass or another known method line), or extracting the fenced-body portion and asserting it’s non-empty.

Suggested change
assert(out.contains("CellarJavaClass"), s"Expected source body in: $out")
assert(out.contains("public class CellarJavaClass"), s"Expected source body in: $out")

Copilot uses AI. Check for mistakes.
Comment thread lib/src/cellar/SourceFetcher.scala Outdated
Comment on lines +43 to +46
val allLines = scala.io.Source.fromInputStream(zip.getInputStream(e), "UTF-8")
.getLines().toIndexedSeq
val extracted = allLines.slice(startLine, endLine + 1)
val extracted = if endLine == Int.MaxValue then allLines.drop(startLine)
else allLines.slice(startLine, endLine + 1)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scala.io.Source.fromInputStream(zip.getInputStream(e), ...) is never closed. Even though the ZipFile is closed in finally, the entry InputStream/Source should be explicitly closed (e.g. via scala.util.Using.resource) to avoid leaking file handles if this method is called repeatedly or if an exception occurs mid-read.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why not fs2?

@rochala rochala merged commit 4a77052 into main Apr 23, 2026
5 checks passed
@rochala rochala deleted the worktree-issue-56 branch April 23, 2026 10:15
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.

get-source returns empty body for Java symbols due to Int.MaxValue overflow

2 participants