-
Notifications
You must be signed in to change notification settings - Fork 917
Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block #9070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| .input("package test;\n" | ||
| + "import java.io.ByteArrayOutputStream;\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: new test code could use multi line Strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
lahodaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, thanks!
| gen.copyComments(tt.getFinallyBlock(), nt, false); | ||
| } | ||
| } | ||
| if(! preVarDeclsWritten) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit - could be if(! preVarDeclsWritten -> if (!preVarDeclsWritten (space moved after if), but it is not critical.
| .input("package test;\n" | ||
| + "import java.io.ByteArrayOutputStream;\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
…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
|
Thanks for review. Given the small size of the PR I updated in place. |
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