Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block#9070
Merged
matthiasblaesing merged 1 commit intoapache:masterfrom Dec 13, 2025
Conversation
mbien
reviewed
Dec 9, 2025
Comment on lines
+1562
to
+1563
| .input("package test;\n" | ||
| + "import java.io.ByteArrayOutputStream;\n" |
Member
There was a problem hiding this comment.
nitpick: new test code could use multi line Strings.
lahodaj
approved these changes
Dec 9, 2025
Contributor
lahodaj
left a comment
There was a problem hiding this comment.
Makes sense to me, thanks!
| gen.copyComments(tt.getFinallyBlock(), nt, false); | ||
| } | ||
| } | ||
| if(! preVarDeclsWritten) { |
Contributor
There was a problem hiding this comment.
Nit - could be if(! preVarDeclsWritten -> if (!preVarDeclsWritten (space moved after if), but it is not critical.
Comment on lines
+1562
to
+1563
| .input("package test;\n" | ||
| + "import java.io.ByteArrayOutputStream;\n" |
…aration) is guarded and other variables are used outside the new block
Example:
============== Source ==============
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
public class Test {
public static byte[] test(InputStream input) throws Exception {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int len;
byte[] buffer = new byte[1024];
while ((len = input.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
input.close();
return outStream.toByteArray();
}
}
============== Result ==============
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
public class Test {
public static byte[] test(InputStream input) throws Exception {
try (input) {
outStream = new ByteArrayOutputStream();
int len;
byte[] buffer = new byte[1024];
while ((len = input.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
}
return outStream.toByteArray();
}
}
====================================
Problem is here, that the result variable is used outside the new try
block, but the declaration is not written.
Closes: apache#9046
72a9dff to
b4fc2c9
Compare
Contributor
Author
|
Thanks for review. Given the small size of the PR I updated in place. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Example:
Rewrite result before fix:
Problem is here, that the result variable is used outside the new try block, but the declaration is not written.
Closes: #9046