mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
MismatchedArrayReadWrite: do not consider compound assignments/increments as reads (IDEA-CR-41955)
This commit is contained in:
+2
-1
@@ -256,8 +256,9 @@ public class MismatchedArrayReadWriteInspection extends BaseInspection {
|
||||
}
|
||||
if (PsiUtil.isAccessedForWriting(arrayAccessExpression)) {
|
||||
myWritten = true;
|
||||
// compound writes like += are not considered as reads, because result result goes to the same array as well
|
||||
}
|
||||
if (PsiUtil.isAccessedForReading(arrayAccessExpression) && !goesToSameArray(arrayAccessExpression)) {
|
||||
else if (PsiUtil.isAccessedForReading(arrayAccessExpression) && !goesToSameArray(arrayAccessExpression)) {
|
||||
myRead = true;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -109,9 +109,10 @@ public class MismatchedArrayReadWrite {
|
||||
}
|
||||
|
||||
void reuseSelf() {
|
||||
int[] arr = new int[10];
|
||||
int[] <warning descr="Contents of array 'arr' are written to, but never read">arr</warning> = new int[10];
|
||||
for(int i=0; i<arr.length; i++) arr[i] = i;
|
||||
for(int i=1; i<arr.length; i++) arr[i] += arr[i-1];
|
||||
for(int i=1; i<arr.length; i++) arr[i] = arr[i-1] + 1;
|
||||
}
|
||||
|
||||
void objectType(Object x) {
|
||||
@@ -135,8 +136,14 @@ class Test{
|
||||
}
|
||||
|
||||
private void testStuff() {
|
||||
int[][] <warning descr="Contents of array 'array' are written to, but never read">array</warning> = new int[2][2];
|
||||
array[0][1]++;
|
||||
}
|
||||
|
||||
private void testStuff2() { // IDEA-47651
|
||||
int[][] array = new int[2][2];
|
||||
array[0][1]++;
|
||||
System.out.println(array[0][1]);
|
||||
}
|
||||
|
||||
void foo1() {
|
||||
|
||||
Reference in New Issue
Block a user