Commit b4fc2c9
committed
Java ConvertToARM fix: Fix case where existing variable (without declaration) 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: #90461 parent 190f8f3 commit b4fc2c9
File tree
2 files changed
+64
-1
lines changed- java/java.hints
- src/org/netbeans/modules/java/hints/jdk
- test/unit/src/org/netbeans/modules/java/hints/jdk
2 files changed
+64
-1
lines changedLines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
612 | 612 | | |
613 | 613 | | |
614 | 614 | | |
| 615 | + | |
615 | 616 | | |
616 | 617 | | |
617 | 618 | | |
618 | 619 | | |
619 | 620 | | |
620 | | - | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
621 | 625 | | |
622 | 626 | | |
623 | 627 | | |
| |||
658 | 662 | | |
659 | 663 | | |
660 | 664 | | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
661 | 669 | | |
662 | 670 | | |
663 | 671 | | |
| |||
667 | 675 | | |
668 | 676 | | |
669 | 677 | | |
| 678 | + | |
670 | 679 | | |
671 | 680 | | |
672 | 681 | | |
| |||
Lines changed: 54 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1554 | 1554 | | |
1555 | 1555 | | |
1556 | 1556 | | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
1557 | 1611 | | |
0 commit comments