Suppress unused-local-variable warnings in test inputs

Test code can do many things we'd consider bad style in real
application code, including defining local variables that are never
subsequently used.
This commit is contained in:
Ben Liblit 2017-05-12 18:09:00 +02:00 committed by Manu Sridharan
parent dee2412ab5
commit 24fb1f6d10
39 changed files with 50 additions and 5 deletions

View File

@ -20,6 +20,7 @@ public class Array1 {
ary[i]= i; ary[i]= i;
} }
@SuppressWarnings("unused")
int sum = 0; int sum = 0;
for(int j= 0; j < ary.length; j++) { for(int j= 0; j < ary.length; j++) {

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*****************************************************************************/ *****************************************************************************/
public class ArrayLiteral1 { public class ArrayLiteral1 {
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
ArrayLiteral1 al1= new ArrayLiteral1(); ArrayLiteral1 al1= new ArrayLiteral1();
int[] a= new int[] { 0, 1, 2, 3, 5 }; int[] a= new int[] { 0, 1, 2, 3, 5 };

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*****************************************************************************/ *****************************************************************************/
public class ArrayLiteral2 { public class ArrayLiteral2 {
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
ArrayLiteral2 al2= new ArrayLiteral2(); ArrayLiteral2 al2= new ArrayLiteral2();
int[] x= {}; int[] x= {};

View File

@ -14,6 +14,7 @@ public class Casts {
(new Casts()).test(args); (new Casts()).test(args);
} }
@SuppressWarnings("unused")
private void test(String[] args) { private void test(String[] args) {
long l1 = Long.parseLong(args[0]); long l1 = Long.parseLong(args[0]);
int i1 = Integer.parseInt(args[1]); int i1 = Integer.parseInt(args[1]);

View File

@ -11,6 +11,7 @@
public class DefaultConstructors { public class DefaultConstructors {
public static void main(String args[]) { public static void main(String args[]) {
@SuppressWarnings("unused")
E e = new E(); E e = new E();
// System.out.println(e.x); // System.out.println(e.x);
// System.out.println(e.y); // System.out.println(e.y);

View File

@ -11,6 +11,7 @@
public class Exception1 { public class Exception1 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
Exception1 e1= new Exception1(); Exception1 e1= new Exception1();
try { try {
FooEx1 f = new FooEx1(); FooEx1 f = new FooEx1();

View File

@ -16,6 +16,7 @@ import java.io.IOException;
public final class Exception2 { public final class Exception2 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
Exception2 e2= new Exception2(); Exception2 e2= new Exception2();
FileInputStream fis = null; FileInputStream fis = null;
FileOutputStream fos = null; FileOutputStream fos = null;

View File

@ -10,6 +10,7 @@
*****************************************************************************/ *****************************************************************************/
public class Finally1 { public class Finally1 {
public static void main(String[] args) throws BadLanguageExceptionF1 { public static void main(String[] args) throws BadLanguageExceptionF1 {
@SuppressWarnings("unused")
Finally1 f1= new Finally1(); Finally1 f1= new Finally1();
try { try {
FooF1 f = new FooF1(); FooF1 f = new FooF1();

View File

@ -10,6 +10,7 @@
*****************************************************************************/ *****************************************************************************/
public class Inheritance1 { public class Inheritance1 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
Inheritance1 ih1= new Inheritance1(); Inheritance1 ih1= new Inheritance1();
Base b1 = new Base(); Base b1 = new Base();
Base b2 = new Derived(); Base b2 = new Derived();
@ -22,6 +23,7 @@ public class Inheritance1 {
} }
class Base { class Base {
public void foo() { public void foo() {
@SuppressWarnings("unused")
int i= 0; int i= 0;
} }
public String bar(int x) { public String bar(int x) {

View File

@ -10,6 +10,7 @@
*****************************************************************************/ *****************************************************************************/
public class InheritedField { public class InheritedField {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
InheritedField if1= new InheritedField(); InheritedField if1= new InheritedField();
B b = new B(); B b = new B();

View File

@ -22,6 +22,7 @@ public class InnerClass {
} }
public void method() { public void method() {
@SuppressWarnings("unused")
WhatsIt w= new WhatsIt(); WhatsIt w= new WhatsIt();
} }

View File

@ -52,6 +52,7 @@ public class InnerClassA {
AB ab = new AB(); AB ab = new AB();
AB.ABSubA absuba = ab.new ABSubA(); AB.ABSubA absuba = ab.new ABSubA();
absuba.aba_x = 7; absuba.aba_x = 7;
@SuppressWarnings("unused")
AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X() AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X()
AB.ABA aba = ab.new ABA(); AB.ABA aba = ab.new ABA();

View File

@ -47,6 +47,7 @@ public class InnerClassLexicalReads {
* 4 invokevirtual < Source, Ljava/io/PrintStream, println(I)V > v7,v8 @4 exception:v10[18:2] -> [18:38] * 4 invokevirtual < Source, Ljava/io/PrintStream, println(I)V > v7,v8 @4 exception:v10[18:2] -> [18:38]
*/ */
public static void main(String args[]) { public static void main(String args[]) {
@SuppressWarnings("unused")
InnerClassLexicalReads ignored = new InnerClassLexicalReads(); // call this just to make <init> reachable (test checks for unreachable methods) InnerClassLexicalReads ignored = new InnerClassLexicalReads(); // call this just to make <init> reachable (test checks for unreachable methods)
int foo = 5; int foo = 5;
int haha = foo * foo; int haha = foo * foo;

View File

@ -10,8 +10,10 @@
*****************************************************************************/ *****************************************************************************/
public class InterfaceTest1 { public class InterfaceTest1 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
InterfaceTest1 it= new InterfaceTest1(); InterfaceTest1 it= new InterfaceTest1();
IFoo foo = new FooIT1('a'); IFoo foo = new FooIT1('a');
@SuppressWarnings("unused")
char ch2 = foo.getValue(); char ch2 = foo.getValue();
} }
} }

View File

@ -11,6 +11,7 @@
public class NullArrayInit { public class NullArrayInit {
String[] x = {null}; String[] x = {null};
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
new NullArrayInit(); new NullArrayInit();
Object a[] = new Object[] {null,null}; Object a[] = new Object[] {null,null};

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*****************************************************************************/ *****************************************************************************/
public class QualifiedStatic { public class QualifiedStatic {
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
QualifiedStatic qs= new QualifiedStatic(); QualifiedStatic qs= new QualifiedStatic();
FooQ fq= new FooQ(); FooQ fq= new FooQ();

View File

@ -10,6 +10,7 @@
*****************************************************************************/ *****************************************************************************/
public class Scoping1 { public class Scoping1 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
Scoping1 s1= new Scoping1(); Scoping1 s1= new Scoping1();
{ {
int x= 5; int x= 5;

View File

@ -10,6 +10,7 @@
*****************************************************************************/ *****************************************************************************/
public class Scoping2 { public class Scoping2 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
Scoping2 s2 = new Scoping2(); Scoping2 s2 = new Scoping2();
{ {
final int x = 5; final int x = 5;

View File

@ -19,6 +19,7 @@ public class Simple1 {
this(0); this(0);
} }
public static void doStuff(int N) { public static void doStuff(int N) {
@SuppressWarnings("unused")
int prod = 1; int prod = 1;
for(int j=0; j < N; j++) for(int j=0; j < N; j++)
prod *= j; prod *= j;

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*****************************************************************************/ *****************************************************************************/
public class StaticNesting { public class StaticNesting {
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
StaticNesting sn= new StaticNesting(); StaticNesting sn= new StaticNesting();
WhatsIt w= new WhatsIt(); WhatsIt w= new WhatsIt();

View File

@ -18,6 +18,7 @@ public class TwoClasses {
this(0); this(0);
} }
public static void doStuff(int N) { public static void doStuff(int N) {
@SuppressWarnings("unused")
int prod= 1; int prod= 1;
TwoClasses tc= new TwoClasses(); TwoClasses tc= new TwoClasses();
tc.instanceMethod1(); tc.instanceMethod1();
@ -35,6 +36,7 @@ public class TwoClasses {
instanceMethod2(); instanceMethod2();
} }
public void instanceMethod2() { public void instanceMethod2() {
@SuppressWarnings("unused")
Bar b= Bar.create('a'); Bar b= Bar.create('a');
} }
} }

View File

@ -10,6 +10,7 @@
*****************************************************************************/ *****************************************************************************/
public class WhileTest1 { public class WhileTest1 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
WhileTest1 wt1= new WhileTest1(); WhileTest1 wt1= new WhileTest1();
int x= 235834; int x= 235834;
boolean stop= false; boolean stop= false;

View File

@ -87,6 +87,7 @@ public class InnerClassAA {
AB ab = new AB(); AB ab = new AB();
AB.ABSubA absuba = ab.new ABSubA(); AB.ABSubA absuba = ab.new ABSubA();
absuba.aba_x = 7; absuba.aba_x = 7;
@SuppressWarnings("unused")
AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X() AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X()
AB.ABA aba = ab.new ABA(); AB.ABA aba = ab.new ABA();

View File

@ -42,6 +42,7 @@ public class ArraysAndSuch {
public static void main(String args[]) { public static void main(String args[]) {
ArraysAndSuch.main(); ArraysAndSuch.main();
} }
@SuppressWarnings("unused")
public static void main() { public static void main() {
Object o1 = null; Object o1 = null;
Object[] os1 = new Object[] { null, o1, null }; Object[] os1 = new Object[] { null, o1, null };

View File

@ -101,6 +101,7 @@ public class ConstructorsAndInitializers extends Super {
class T{ class T{
} }
@SuppressWarnings("unused")
T t = new T(); T t = new T();
} }
} }

View File

@ -40,6 +40,7 @@ package foo.bar.hello.world;
public class CopyOfLoopsAndLabels { public class CopyOfLoopsAndLabels {
static int X=5; static int X=5;
public static void main(String args[]) { public static void main(String args[]) {
@SuppressWarnings("unused")
int k=X; int k=X;
for (; ; k++) for (; ; k++)
break; break;

View File

@ -87,6 +87,7 @@ public class InnerClasses extends Temp {
se2.setSEVar(); se2.setSEVar();
System.out.println(sub2.hello()); //1001 System.out.println(sub2.hello()); //1001
@SuppressWarnings("unused")
int foo = 12; int foo = 12;
foo++; foo++;
--foo; --foo;

View File

@ -40,6 +40,7 @@ package foo.bar.hello.world;
public class MiniaturList2 { public class MiniaturList2 {
public static void main(String[] args) { public static void main(String[] args) {
@SuppressWarnings("unused")
int a; int a;
for ( ;; ) { for ( ;; ) {
break; break;

View File

@ -113,11 +113,13 @@ public class CustomGenericsAndFields {
///////////////////////////// /////////////////////////////
@SuppressWarnings("unused")
String thrownaway = cg2.bar("a","b"); String thrownaway = cg2.bar("a","b");
cg2.setFoo("real one"); cg2.setFoo("real one");
MyGeneric<String,ConcreteGeneric2<String>> mygeneric = new MyGeneric<String,ConcreteGeneric2<String>>("useless",cg2); MyGeneric<String,ConcreteGeneric2<String>> mygeneric = new MyGeneric<String,ConcreteGeneric2<String>>("useless",cg2);
String x = mygeneric.doFoo(); String x = mygeneric.doFoo();
System.out.println(x); System.out.println(x);
@SuppressWarnings("unused")
String y = cg2.x; String y = cg2.x;
System.out.println(mygeneric.getB().y); System.out.println(mygeneric.getB().y);
System.out.println(mygeneric.b.y); // TODO: fields are going to be a pain... watch out for Lvalues in context? System.out.println(mygeneric.b.y); // TODO: fields are going to be a pain... watch out for Lvalues in context?

View File

@ -47,6 +47,7 @@ public class ExplicitBoxingTest {
int a = 6; int a = 6;
a = a + a; a = a + a;
System.out.println(a); System.out.println(a);
@SuppressWarnings("unused")
Integer useless1 = new Integer(5+6); Integer useless1 = new Integer(5+6);
Integer aa = new Integer(a+a); Integer aa = new Integer(a+a);
int aaa = aa.intValue(); int aaa = aa.intValue();
@ -55,6 +56,7 @@ public class ExplicitBoxingTest {
int b = 6; int b = 6;
b = b + b; b = b + b;
System.out.println(b); System.out.println(b);
@SuppressWarnings("unused")
Integer useless2 = 5+6; Integer useless2 = 5+6;
Integer bb = b+b; Integer bb = b+b;
int bbb = bb; int bbb = bb;

View File

@ -52,6 +52,7 @@ public class GenericArrays {
List<Integer> li = new ArrayList<Integer>(); List<Integer> li = new ArrayList<Integer>();
li.add(new Integer(3)); li.add(new Integer(3));
oa[1] = li; // correct oa[1] = li; // correct
@SuppressWarnings("unused")
String s = (String) lsa[1].get(0); // run time error, but cast is explicit String s = (String) lsa[1].get(0); // run time error, but cast is explicit
} }

View File

@ -13,6 +13,7 @@ package javaonepointfive;
public class TypeInferencePrimAndStringOp { public class TypeInferencePrimAndStringOp {
public static void main(String[] args) { public static void main(String[] args) {
int a = 2; int a = 2;
@SuppressWarnings("unused")
String result = "a" + a; String result = "a" + a;
} }
} }

View File

@ -11,6 +11,7 @@
package p; package p;
public class NonPrimaryTopLevel { public class NonPrimaryTopLevel {
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
NonPrimaryTopLevel nptl= new NonPrimaryTopLevel(); NonPrimaryTopLevel nptl= new NonPrimaryTopLevel();
Foo f = new Foo(); Foo f = new Foo();

View File

@ -67,11 +67,11 @@ public abstract class JavaIRTests extends IRTests {
@Test public void testSimple1() throws IllegalArgumentException, CancelException, IOException { @Test public void testSimple1() throws IllegalArgumentException, CancelException, IOException {
List<? extends IRAssertion> assertions = Arrays.asList( List<? extends IRAssertion> assertions = Arrays.asList(
new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "prod", 24), new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "prod", 25),
new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "j", 23), new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "j", 24),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "s", 32), new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "s", 33),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "i", 28), new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "i", 29),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "sum", 29), new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "sum", 30),
EdgeAssertions.make("Source#Simple1#main#([Ljava/lang/String;)V", "Source#Simple1#doStuff#(I)V"), EdgeAssertions.make("Source#Simple1#main#([Ljava/lang/String;)V", "Source#Simple1#doStuff#(I)V"),
EdgeAssertions.make("Source#Simple1#instanceMethod1#()V", "Source#Simple1#instanceMethod2#()V")); EdgeAssertions.make("Source#Simple1#instanceMethod1#()V", "Source#Simple1#instanceMethod2#()V"));

View File

@ -44,6 +44,7 @@ public class CPATest1 {
return x; return x;
} }
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
F f = new F(3.4); F f = new F(3.4);
I i = new I(7); I i = new I(7);

View File

@ -44,6 +44,7 @@ public class CPATest2 {
return x; return x;
} }
@SuppressWarnings("unused")
public static void main(String[] args) { public static void main(String[] args) {
F f = new F(3.4); F f = new F(3.4);
I i = new I(7); I i = new I(7);

View File

@ -14,6 +14,7 @@ public class TestStaticInitOrder {
private static class A { private static class A {
@SuppressWarnings("unused")
static int f; static int f;
static { static {
@ -26,6 +27,7 @@ public class TestStaticInitOrder {
} }
private static class B { private static class B {
@SuppressWarnings("unused")
static int b; static int b;
static { static {
@ -39,6 +41,7 @@ public class TestStaticInitOrder {
private static class C extends B { private static class C extends B {
@SuppressWarnings("unused")
static int c = 5; static int c = 5;
public static void dostuff() { public static void dostuff() {

View File

@ -399,6 +399,7 @@ public class CallGraphTest extends WalaTestCase {
} }
// perform a little icfg exercise // perform a little icfg exercise
@SuppressWarnings("unused")
int count = 0; int count = 0;
for (Iterator<BasicBlockInContext<ISSABasicBlock>> it = icfg.iterator(); it.hasNext();) { for (Iterator<BasicBlockInContext<ISSABasicBlock>> it = icfg.iterator(); it.hasNext();) {
BasicBlockInContext<ISSABasicBlock> bb = it.next(); BasicBlockInContext<ISSABasicBlock> bb = it.next();

View File

@ -48,6 +48,7 @@ public class LambdaTest extends WalaTestCase {
"Lbug144/A"); "Lbug144/A");
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
@SuppressWarnings("unused")
CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(), cha, scope, false); CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(), cha, scope, false);
} }