You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "matthiasblaesing (via GitHub)" <gi...@apache.org> on 2025/12/05 18:48:51 UTC
[PR] Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block [netbeans]
matthiasblaesing opened a new pull request, #9070:
URL: https://github.com/apache/netbeans/pull/9070
Example:
```java
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();
}
}
```
```java
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: #9046
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #9070:
URL: https://github.com/apache/netbeans/pull/9070#issuecomment-3633730539
Thanks for review. Given the small size of the PR I updated in place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #9070:
URL: https://github.com/apache/netbeans/pull/9070#discussion_r2601888226
##########
java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToARMTest.java:
##########
@@ -1554,4 +1554,54 @@ public void testPreserveComments228141() throws Exception {
}
}
}
+
+ // Case:
+ public void testGH9046() throws Exception {
+ HintTest
+ .create()
+ .input("package test;\n"
+ + "import java.io.ByteArrayOutputStream;\n"
Review Comment:
nitpick: new test code could use multi line Strings.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #9070:
URL: https://github.com/apache/netbeans/pull/9070#discussion_r2603380747
##########
java/java.hints/test/unit/src/org/netbeans/modules/java/hints/jdk/ConvertToARMTest.java:
##########
@@ -1554,4 +1554,54 @@ public void testPreserveComments228141() throws Exception {
}
}
}
+
+ // Case:
+ public void testGH9046() throws Exception {
+ HintTest
+ .create()
+ .input("package test;\n"
+ + "import java.io.ByteArrayOutputStream;\n"
Review Comment:
+1
##########
java/java.hints/src/org/netbeans/modules/java/hints/jdk/ConvertToARM.java:
##########
@@ -658,6 +662,10 @@ private static BlockTree rewriteOwnerBlock(
gen.copyComments(tt.getFinallyBlock(), nt, false);
}
}
+ if(! preVarDeclsWritten) {
Review Comment:
Nit - could be `if(! preVarDeclsWritten` -> `if (!preVarDeclsWritten` (space moved after `if`), but it is not critical.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Java ConvertToARM fix: Fix case where existing variable (without declaration) is guarded and other variables are used outside the new block [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing merged PR #9070:
URL: https://github.com/apache/netbeans/pull/9070
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists