-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #11920: fix false positive UnusedLocalVariableCheck
- Loading branch information
1 parent
3eca7e0
commit 472fbc8
Showing
3 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
.../checkstyle/checks/coding/unusedlocalvariable/InputUnusedLocalVariableNestedClasses3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
UnusedLocalVariable | ||
*/ | ||
|
||
package com.puppycrawl.tools.checkstyle.checks.coding.unusedlocalvariable; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
public class InputUnusedLocalVariableNestedClasses3 { | ||
void method() { | ||
final OuterClass outerClass = new OuterClass(); // ok | ||
final OuterClass.InnerClass innerClass = outerClass.new InnerClass(); | ||
System.out.println(innerClass); | ||
} | ||
|
||
class OuterClass { | ||
class InnerClass { | ||
InnerClass() { } | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
class Outer { | ||
public class Inner { } | ||
} | ||
|
||
class Test { | ||
void m() { | ||
@A Outer p1 = new @A Outer(); // ok | ||
// violation below 'Unused local variable 'p2'.' | ||
@A Outer.@B Inner p2 = p1.new @B Inner(); | ||
} | ||
|
||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@interface A { } | ||
|
||
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) | ||
@interface B { } | ||
} | ||
|
||
class H006_ComplexConstructors<T> { | ||
public <V> H006_ComplexConstructors(T t, V v) { } | ||
|
||
class Inner3 { | ||
Inner3(int x) { | ||
H006_ComplexConstructors<Integer> instance = // ok | ||
new <String>H006_ComplexConstructors<Integer>(0, ""); | ||
// violation below 'Unused local variable 'o'.' | ||
Object o = instance.new Inner3(5).new <String>InnerInner3("hey"); | ||
} | ||
|
||
class InnerInner3 { | ||
<D> InnerInner3(D in) { } | ||
} | ||
} | ||
} | ||
|
||
class NullQualifiedNew2 { | ||
class Inner { | ||
Inner(int i) {} | ||
} | ||
|
||
public static void main(String[] args) { | ||
int i = 1; | ||
a: try { | ||
NullQualifiedNew2 c = null; | ||
c.new Inner(i++) {}; | ||
} catch (NullPointerException e) { | ||
break a; | ||
} | ||
if (i != 1) throw new Error("i = " + i); | ||
} | ||
} | ||
|
||
class T7090499<E> { | ||
|
||
static class B<X> { } | ||
|
||
class A<X> { | ||
class X { } | ||
|
||
class Z<Y> { } | ||
} | ||
|
||
T7090499 t = new T7090499() { | ||
void test(Object arg1, B arg2) { | ||
// violation below 'Unused local variable 'b'.' | ||
boolean b = arg1 instanceof A; | ||
// violation below 'Unused local variable 'a'.' | ||
Object a = (A) arg1; | ||
A a2 = new A() { }; | ||
a2.new Z() { }; | ||
} | ||
}; | ||
} |