package com.siyeh.igtest.bugs.mismatched_array_read_write;
public class MismatchedArrayReadWrite {
- private int[] foo = new int[3];
- private int[] bar;
+ private int[] <warning descr="Contents of array 'foo' are written to, but never read">foo</warning> = new int[3];
+ private int[] <warning descr="Contents of array 'bar' are read, but never written to">bar</warning>;
public void bar()
{
public void bar2()
{
- final int[] barzoom = new int[3];
+ final int[] <warning descr="Contents of array 'barzoom' are written to, but never read">barzoom</warning> = new int[3];
barzoom[2] = 3;
}
public void bar3()
{
- final int[] barzoom = new int[3];
+ final int[] <warning descr="Contents of array 'barzoom' are read, but never written to">barzoom</warning> = new int[3];
int baz = barzoom[2];
}
public int bar5()
{
- final int[] barzoom = new int[3];
+ final int[] <warning descr="Contents of array 'barzoom' are read, but never written to">barzoom</warning> = new int[3];
return barzoom[3];
}
public void bar6()
{
- final int[] barzoom = new int[3];
+ final int[] <warning descr="Contents of array 'barzoom' are read, but never written to">barzoom</warning> = new int[3];
System.out.println(barzoom[3]);
}
}
void foo1() {
- final int[] barzoom = {};
+ final int[] <warning descr="Contents of array 'barzoom' are written to, but never read">barzoom</warning> = {};
barzoom[2] = 3;
}
void foo2() {
- final int[] barzoom = new int[]{};
+ final int[] <warning descr="Contents of array 'barzoom' are written to, but never read">barzoom</warning> = new int[]{};
barzoom[2] = 3;
}
void foo3(Object[] otherArr) {
- Object[] arr = otherArr.clone();
+ Object[] <warning descr="Contents of array 'arr' are written to, but never read">arr</warning> = otherArr.clone();
for (int i = 0; i < 10; i++) arr[i] = i;
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<problems>
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>20</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>barzoom</code> are read, but never written to #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>32</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>barzoom</code> are read, but never written to #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>14</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>barzoom</code> are written to, but never read #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>38</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>barzoom</code> are read, but never written to #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>5</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>bar</code> are read, but never written to #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>4</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>foo</code> are written to, but never read #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>90</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>barzoom</code> are written to, but never read #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>100</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>arr</code> are written to, but never read #loc</description>
- </problem>
-
- <problem>
- <file>MismatchedArrayReadWrite.java</file>
- <line>95</line>
- <problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Mismatched read and write of array</problem_class>
- <description>Contents of array <code>barzoom</code> are written to, but never read #loc</description>
- </problem>
-
-</problems>
\ No newline at end of file
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package com.siyeh.ig.bugs;
-import com.siyeh.ig.IGInspectionTestCase;
+import com.intellij.codeInspection.InspectionProfileEntry;
+import com.siyeh.ig.LightInspectionTestCase;
+import org.jetbrains.annotations.Nullable;
-public class MismatchedArrayReadWriteInspectionTest extends IGInspectionTestCase {
+public class MismatchedArrayReadWriteInspectionTest extends LightInspectionTestCase {
- public void test() throws Exception {
- doTest("com/siyeh/igtest/bugs/mismatched_array_read_write",
- new MismatchedArrayReadWriteInspection());
+ public void testMismatchedArrayReadWrite() {
+ doTest();
+ }
+
+ @Nullable
+ @Override
+ protected InspectionProfileEntry getInspection() {
+ return new MismatchedArrayReadWriteInspection();
+ }
+
+ @Override
+ protected String[] getEnvironmentClasses() {
+ return new String[] {
+ "package java.io;" +
+ "public class ObjectStreamField {" +
+ " public ObjectStreamField(String name, Class<?> type) {}" +
+ "}"
+ };
}
}
\ No newline at end of file