java highlighting tests moved to community

This commit is contained in:
Alexey Kudravtsev
2010-06-25 12:46:38 +04:00
parent 7ec040c1ec
commit 735a9d17a8
243 changed files with 22082 additions and 0 deletions
@@ -0,0 +1,109 @@
// abstract methods
public class a {
<error descr="Missing method body, or declare abstract">void f();</error>
}
abstract class c1 {
abstract void f1();
<error descr="Missing method body, or declare abstract">int f2();</error>
}
interface ff {
abstract void f1();
void f2();
}
class x {
void f() {
<error descr="Method call expected">RuntimeException()</error>;
throw <error descr="Method call expected">RuntimeException()</error>;
}
}
// -------------------------------------------------------------
<error descr="Class 'c2' must either be declared abstract or implement abstract method 'f()' in 'c2'">class c2</error> {
<error descr="Abstract method in non-abstract class">abstract</error> void f();
}
<error descr="Class 'c3' must either be declared abstract or implement abstract method 'iif()' in 'c4'">class c3 extends c4</error> {
}
abstract class c4 {
abstract void iif();
}
class c5 extends c6 implements i7 { public void ff(){} }
abstract class c6 {}
interface i7 { void ff(); }
<error descr="Class 'c7' must either be declared abstract or implement abstract method 'ff()' in 'i7'">class c7 implements i7</error> {
}
class callabstract extends c4 {
void iif() {
<error descr="Abstract method 'iif()' cannot be accessed directly">super.iif()</error>;
}
}
abstract class c8 {
public abstract boolean equals(Object other);
}
<error descr="Class 'c9' must either be declared abstract or implement abstract method 'equals(Object)' in 'c8'">final class c9 extends c8</error> {
}
//------- if only Bottom were in other package, it should have been abstract --------------------------
public abstract class AbstractTest {
abstract String getName();
abstract static class Middle extends AbstractTest {
}
static class Bottom extends Middle {
String getName() {
return null;
}
}
}
///////////
abstract class cc1 {
abstract void f(int i);
}
abstract class cc2 extends cc1 {
abstract protected void f(int i);
}
class cc3 extends cc2 {
public void f(int i) {}
}
///////////////
interface MyComparator {
int compare(Object t, Object t1);
boolean equals(java.lang.Object object);
}
class MyComparatorImpl implements MyComparator {
public int compare(Object o, Object o1) {
new MyComparator() {
public int compare(Object o, Object o1) {
return 0;
}
};
return 0;
}
}
//////////////// IDEADEV-6050
interface Comparable {}
interface PublicCloneable extends Cloneable {
Object clone() throws CloneNotSupportedException;
}
interface PublicCloneableExtension extends Comparable, PublicCloneable {
}
@@ -0,0 +1,87 @@
// access level clashes
interface i {
void ff();
}
public class a implements i {
void <error descr="'ff()' in 'a' clashes with 'ff()' in 'i'; attempting to assign weaker access privileges ('packageLocal'); was 'public'">ff</error>() {}
}
class ai implements i {
public <error descr="'ff()' in 'ai' clashes with 'ff()' in 'i'; attempting to use incompatible return type">int</error> ff() { return 0;}
}
class c2 implements i {
public c2() {}
public void ff() {}
protected void g() {}
private int fff(String s) { return 0; }
}
class c3 extends c2 {
protected c3() {}
private int g(int k) { return 2;}
private char fff(String s) { return 0; }
}
class c4 extends c3 {
private c4() {}
<error descr="'g()' in 'c4' clashes with 'g()' in 'c2'; attempting to assign weaker access privileges ('private'); was 'protected'">private</error> void g() {}
private String fff(String s) throws java.io.IOException { return null; }
}
class c4i extends c3 {
protected <error descr="'g()' in 'c4i' clashes with 'g()' in 'c2'; attempting to use incompatible return type">Object</error> g() {return null;}
}
// sibling inheritance
abstract class c5 { abstract public int ff(); }
interface i5 { void ff(); }
<error descr="'ff()' in 'i5' clashes with 'ff()' in 'c5'; methods have unrelated return types">abstract class c6 extends c5 implements i5</error> {
}
class c7 { public String ff() { return null;} }
<error descr="'ff()' in 'c7' clashes with 'ff()' in 'i5'; attempting to use incompatible return type">class c8 extends c7 implements i5</error> {
}
// interface should not clash with Object
interface A {
Object clone() throws CloneNotSupportedException;
void finalize();
<error descr="'hashCode()' in 'A' clashes with 'hashCode()' in 'java.lang.Object'; attempting to use incompatible return type">void</error> hashCode();
<error descr="'equals(Object)' in 'A' clashes with 'equals(Object)' in 'java.lang.Object'; attempting to use incompatible return type">void</error> equals(Object o);
<error descr="'toString()' in 'A' clashes with 'toString()' in 'java.lang.Object'; attempting to use incompatible return type">void</error> toString();
}
interface ConflictWithObject {
Object clone() throws CloneNotSupportedException;
}
<error descr="'clone()' in 'java.lang.Object' clashes with 'clone()' in 'ConflictWithObject'; attempting to assign weaker access privileges ('protected'); was 'public'">class s implements ConflictWithObject</error> {
}
// parallel overriding methods from Object
interface InderFace {
Object clone() throws CloneNotSupportedException;
}
interface SubInderFace extends InderFace {
}
<error descr="'clone()' in 'java.lang.Object' clashes with 'clone()' in 'InderFace'; attempting to assign weaker access privileges ('protected'); was 'public'">class Implementation implements SubInderFace</error> {
}
//SCR20002
abstract class SCR20002A extends Object implements Runnable {
protected abstract int getSome();
private final Inner getInner() { return null; }
private class Inner { }
}
abstract class SCR20002B extends SCR20002A implements Runnable {
private final Inner getInner() { return null; }
private class Inner { }
}
abstract class SCR20002C extends SCR20002B implements Runnable {
}
@@ -0,0 +1,35 @@
// Ambiguous method call
class C61 {
public void foo(String s) {}
public void foo(Integer i) {}
public void foo2() {
foo<error descr="Ambiguous method call: both 'C61.foo(String)' and 'C61.foo(Integer)' match">(null)</error>;
}
}
class D61 extends C61 {
public void foo(Integer i) {}
public void foo2() {
foo<error descr="Ambiguous method call: both 'D61.foo(Integer)' and 'C61.foo(String)' match">(null)</error>;
foo<error descr="Cannot resolve method 'foo(int)'">(1)</error>;
}
}
class ex {
void f(String name, String[] i){}
void f(String name, ex i){}
void g() {
f<error descr="Ambiguous method call: both 'ex.f(String, String[])' and 'ex.f(String, ex)' match">("",null)</error>;
}
}
class XX {
XX() {}
void XX() {}
{
new XX().XX();
}
}
@@ -0,0 +1,11 @@
class A{
{
class Local{
void foo(){}
}
new Local(){
void foo(){}
};
}
}
@@ -0,0 +1,21 @@
public class QQQ {
{
new Outer(){
void foo(){
new Inner(){
void method() {
super.method();
}
};
}
};
}
}
class Outer{
class Inner{
void method(){
}
}
}
@@ -0,0 +1,72 @@
// assign to final
import java.io.*;
import java.net.*;
public class a21 {
final int fi;
{
fi = 4;
}
void f1(int i) {
final int j = 4;
<error descr="Cannot assign a value to final variable 'j'">j = 3</error>;
}
void f2(final int i) {
final int j = 4;
<error descr="Cannot assign a value to final variable 'i'">i = 3</error>;
}
void f3( int ip) {
<error descr="Cannot assign a value to final variable 'fi'">fi = 3</error>;
for (final int i = 0; i<3; <error descr="Cannot assign a value to final variable 'i'">i++</error>) {
int k = 4;
}
final int i1 = 0;
<error descr="Cannot assign a value to final variable 'i1'">i1++</error>;
<error descr="Cannot assign a value to final variable 'i1'">--i1</error>;
int i2 = -i1 + ~i1;
final int j = (<error descr="Cannot assign a value to final variable 'j'">j=0</error>) == 1 || j==0 ? 9 : j;
}
static final boolean DEBUG = false;
void f4() {
if (DEBUG && (fi < 3 || fi >4)) return;
}
}
class B extends a21 {
public B() {
<error descr="Cannot assign a value to final variable 'fi'">fi = 0</error>;
}
void f() {
final Integer i;
new Runnable() {
public void run() {
<error descr="Cannot assign a value to final variable 'i'">i = new Integer(4)</error>;
}
};
}
}
class a21_2 {
final int i;
a21_2() {
i = 0;
new Runnable() {
public void run() {
<error descr="Cannot assign a value to final variable 'i'">i = 0</error>;
}
};
}
}
class Foo {
private final Foo next;
public Foo(Foo previous) {
this.next = null;
if (previous != null) {
<error descr="Cannot assign a value to final variable 'next'">previous.next = this</error>;
}
}
}
@@ -0,0 +1,50 @@
// break outside of
public class a {
void f() {
<error descr="Break outside switch or loop">break;</error>
while (true) {
break;
}
do { break; } while (true);
switch (1) {
case 1: break;
}
for (;;) {
break;
}
for (;;) {
new ff() {
void f() {
<error descr="Break outside switch or loop">break;</error>
}
};
break;
}
while (true) {
class s {
{
<error descr="Break outside switch or loop">break;</error>
}
}
break;
}
do {
class s {
{
<error descr="Break outside switch or loop">break;</error>
}
}
break;
} while (true);
}
}
class ff {
}
@@ -0,0 +1,16 @@
abstract public class a1 {
<error descr="Abstract methods cannot have a body">abstract void f()</error> {}
<error descr="Native methods cannot have a body">native void ff()</error> {}
void f2() {
new ii() {
public int iif(int i) {
return 0;
}
};
}
}
interface ii {
<error descr="Interface methods cannot have body">int iif(int i) throws Exception</error> { return 2; }
}
@@ -0,0 +1,8 @@
class K {
public K foo() {
return <error descr="Inconvertible types; cannot cast 'void' to 'K'">(K) bar()</error>;
}
private void bar() {
}
}
@@ -0,0 +1,11 @@
public class MyClass {
public static void main(String[] args) {
try {
<error>unknownMethod</error>(); /* Red code - as expected */
} catch (java.io.IOException e) { /* Unwanted red squiggly line */
e.printStackTrace();
}
}
}
@@ -0,0 +1,20 @@
class A_CR{
public static final int CONST = <error descr="Cannot resolve symbol 'CONSTX'">CONSTX</error>;
{
switch(0){
case <error descr="Constant expression required">CONST</error>:
}
}
}
class AClass {
private static final String SPACE = " ";
class s {
private static final String RET_VAL =
"Roger" +
SPACE +
SPACE + // comment and uncomment this line
" Dodger";
}
}
@@ -0,0 +1,63 @@
// call to super must be first
public class a {
a() {}
a(int i) {}
}
class b extends a {
b() {
int i = 3;
<error descr="Call to 'super()' must be first statement in constructor body">super()</error>;
}
b(int i) {
this();
<error descr="Call to 'super()' must be first statement in constructor body">super(2)</error>;
}
b(char i) {
super(4);
<error descr="Call to 'this()' must be first statement in constructor body">this()</error>;
}
b(String s) {
try {
<error descr="Call to 'super()' must be first statement in constructor body">super(2)</error>;
}
finally {
}
}
b(String s, int i) {
{
<error descr="Call to 'super()' must be first statement in constructor body">super(2)</error>;
}
}
void f() {
<error descr="Call to 'super()' must be first statement in constructor body">super()</error>;
}
void g() {
<error descr="Call to 'this()' must be first statement in constructor body">this()</error>;
}
}
class O extends <error descr="No enclosing instance of type 'A' is in scope">A.B</error>
{
public O(A a)
{
int i = 0;
<error descr="Call to 'a.super()' must be first statement in constructor body">a.super()</error>;
}
public O(A a,int i)
{
a.super();
i = 0;
}
}
class A
{
class B
{
class C{}
}
}
@@ -0,0 +1,62 @@
// deprecated
class a {
/**
* @deprecated
*/
void f() {}
/**
* @deprecated
*/
int dep;
int notdep;
/**
* @deprecated
*/
a(int i,int j,int k) {
new <warning descr="'a(int, int, int)' is deprecated">a</warning>(k+i+j,<warning descr="'dep' is deprecated">dep</warning>,notdep);
}
}
class b extends a {
void <warning descr="Overrides deprecated method in 'a'">f</warning>() {
super.<warning descr="'f()' is deprecated">f</warning>();
}
b() {
<warning descr="'b(int)' is deprecated">this</warning>(1);
}
/**
* @deprecated
*/
b(int i) {
<warning descr="'a(int, int, int)' is deprecated">super</warning>(0,0,i);
System.out.print(i);
}
}
class c extends b {
// b.f is not deprecated
void f() {}
}
interface i1 {
/**
* @deprecated
*/
void f();
}
abstract class ac1 {
/**
* @deprecated
*/
public abstract void f();
}
class ci1 extends ac1 implements i1 {
// no chance not to implement it
public void f() {}
}
@@ -0,0 +1,7 @@
public class A_DBD {
{
int field = 0;
field.
<error descr="Cannot resolve symbol 'String'">String</error> s = null;
}
}
@@ -0,0 +1,75 @@
public class a {
<error descr="'f(int)' is already defined in 'a'">void f(int i)</error> { }
<error descr="'f(int)' is already defined in 'a'">void f(int i)</error> {
new c1() {
<error descr="'f1()' is already defined in 'Anonymous class derived from c1'">public void f1()</error> {}
<error descr="'f1()' is already defined in 'Anonymous class derived from c1'">public void f1()</error> {}
};
}
}
abstract class c1 {
abstract void f1();
}
interface ii {
abstract void f1();
void f2();
}
<error descr="Duplicate class: 'a'">class a</error> {
}
class Foo {
void f() {
class Bar {
}
<error descr="Duplicate class: 'Bar'">class Bar</error> {
}
}
}
class c2 {
class c3 {
void f() {
<error descr="Duplicate class: 'c2'">class c2</error> {
}
}
}
}
class cont {
class B {
}
{
<error descr="Duplicate class: 'B'">class B</error> {
}
}
<error descr="Duplicate class: 'B'">class B</error> {
}
}
class cont2 {
{
class B {
}
}
class B {
}
}
class ok {
class Local{};
class AnotherLocal {
class Local {};
void bar() {
class Local {};
Local l;
}
}
}
class ok2 {
public ok2() {}
public void ok2() {}
}
@@ -0,0 +1,75 @@
public class a {
void f(int i) { }
<error descr="'f(int)' is already defined in 'a'">void f(int i)</error> {
new c1() {
public void f1() {}
<error descr="'f1()' is already defined in 'Anonymous class derived from c1'">public void f1()</error> {}
};
}
}
abstract class c1 {
abstract void f1();
}
interface ii {
abstract void f1();
void f2();
}
<error descr="Duplicate class: 'a'">class a</error> {
}
class Foo {
void f() {
class Bar {
}
<error descr="Duplicate class: 'Bar'">class Bar</error> {
}
}
}
class c2 {
class c3 {
void f() {
<error descr="Duplicate class: 'c2'">class c2</error> {
}
}
}
}
class cont {
class B {
}
{
<error descr="Duplicate class: 'B'">class B</error> {
}
}
<error descr="Duplicate class: 'B'">class B</error> {
}
}
class cont2 {
{
class B {
}
}
class B {
}
}
class ok {
class Local{};
class AnotherLocal {
class Local {};
void bar() {
class Local {};
Local l;
}
}
}
class ok2 {
public ok2() {}
public void ok2() {}
}
@@ -0,0 +1,66 @@
// duplicate labels
import java.io.*;
import java.net.*;
public class a {
final int FI = 4;
void f(final int i) {
switch (i) {
<error descr="Duplicate default label">default:</error> break;
case 1: break;
<error descr="Duplicate default label">default:</error> break;
}
switch (i) {
case <error descr="Duplicate label '1'">1</error>: break;
case <error descr="Duplicate label '1'">1</error>: break;
}
switch (i) {
case <error descr="Duplicate label '1'">FI/2 - 1</error>: break;
case <error descr="Duplicate label '1'">(1 + 35/16)%2</error>: break;
case FI - 8: break;
}
final byte b = 127;
switch(i) {
case <error descr="Duplicate label '127'">b</error>:
System.out.println("b=" + b + ";");
case <error descr="Duplicate label '127'">127</error>:
System.out.println("MySwitch.MySwitch");
}
// internalize strings
switch (0) {
case 0:
case "\410" == "!0" ? 1 : 0:
case ""==""+"" ? 3 : 0:
}
switch (0) {
case 0:
//case 1./0 == Double.POSITIVE_INFINITY ? 1 : 0:
//case 1./0 == Float.POSITIVE_INFINITY ? 2 : 0:
// commented out ref
// does not work when running under JRE
//case -1./0 == Double.NEGATIVE_INFINITY ? 3 : 0:
//case -1./0 == Float.NEGATIVE_INFINITY ? 4 : 0:
//case Double.POSITIVE_INFINITY == Float.POSITIVE_INFINITY ? 5 : 0:
//case Double.NEGATIVE_INFINITY == Float.NEGATIVE_INFINITY ? 6 : 0:
//case Double.NaN != Float.NaN ? 7 : 0:
//case Integer.MIN_VALUE == -2.147483648e9 ? 8 : 0:
//case Integer.MIN_VALUE == -2.14748365e9f ? 9 : 0:
//case Long.MIN_VALUE == -9.223372036854776e18 ? 10 : 0:
//case Long.MIN_VALUE == -9.223372e18f ? 11 : 0:
}
}
}
@@ -0,0 +1,88 @@
// no enclosing instance when inheriting inner class
class A57 {
class X {
}
void f() {
class XL extends A57.X {
}
}
class XXL extends A57.X {
}
}
class B57 {
class X extends <error descr="No enclosing instance of type 'A57' is in scope">A57.X</error> {
}
}
class C57 extends <error descr="No enclosing instance of type 'B57' is in scope">B57.X</error> {
}
class inner_holder {
class inner {}
}
public class C1_57 extends inner_holder {
// inner instance available through inheritance
protected class c extends inner {
private class iii extends inner {}
}
}
/////////////////////////////////////
class ParentA {
class InnerA {
}
}
class ParentB extends ParentA {
static class InnerB extends <error descr="No enclosing instance of type 'ParentA' is in scope">InnerA</error> {
}
class InnerC extends InnerA {
}
}
////////////////////////
class c {
static class s {
void f() {
Object o = this;
}
}
void f() {}
}
class cc {
static class sc extends c {
void f() {
super.f();
}
}
}
///////////////////////////
class A
{
class B
{
class C{}
}
}
class AB extends A.B {
AB(A a) {
a.super();
}
AB() {
this(new A());
}
}
class ABIllegal extends <error descr="No enclosing instance of type 'A' is in scope">A.B</error> {
ABIllegal(A a) {
}
ABIllegal() {
this(new A());
}
}
@@ -0,0 +1,105 @@
// Exception is never thrown in method
import java.io.*;
import java.sql.*;
class a {
private void f() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {
}
public void usef() throws Exception {
f(); //avoid unused f()
}
private void f2() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {
try {
throw new IOException();
}
finally {
return;
}
}
public final void f3() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {
}
public static void f4() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {
}
public void usef2() throws Exception {
f2(); //avoid unused f()
}
public void usef3() throws Exception {
f3(); //avoid unused f()
}
public void usef4() throws Exception {
f4(); //avoid unused f()
}
}
final class Final {
{
new Object() {
void f() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {}
};
}
void f() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {}
public void f1() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {}
protected void f2() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">IOException</warning> {}
}
class a1 {
a1() throws <warning descr="Exception 'java.io.IOException' is never thrown in the method">java.io.IOException</warning>, <warning descr="Exception 'java.sql.SQLException' is never thrown in the method">SQLException</warning>{
}
}
class b1 extends a1 {
b1() throws IOException, SQLException {
}
}
////////////////////////////////
public class FooThrow
{
final Foo foo = new Foo(); // Can throw FooException
FooThrow() throws Foo {
}
}
class Foo extends Exception {
public Foo() throws Foo {
throw new Foo();
}
}
//////////////
class H {
public H() throws FileNotFoundException {
}
{
if(true) {
throw new FileNotFoundException();
}
}
}
class PossibleIdeaBugs implements java.io.Serializable {
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
}
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException, ClassNotFoundException {
}
private Object writeReplace() throws java.io.ObjectStreamException {
return this;
}
private Object readResolve() throws java.io.ObjectStreamException {
return null;
}
}
@@ -0,0 +1,13 @@
import java.io.*;
import java.sql.*;
////////////
class x {
void f() {
try {
int i = 0;
}
catch (<error descr="Exception 'java.io.IOException' is never thrown in the corresponding try block">IOException e</error>) {
}
}
}
@@ -0,0 +1,4 @@
class s {
int i;
class inn extends <error descr="Class name expected">i</error> {}
}
@@ -0,0 +1,223 @@
// final Fields initialization
import java.io.*;
import java.net.*;
import java.awt.event.*;
public class a {
/**
* javadoc should not be highlighted
*/
<error descr="Variable 'javaDoced' might not have been initialized">final int javaDoced</error>;
<error descr="Variable 'sfi1' might not have been initialized">static final int sfi1</error>;
<error descr="Variable 'sfi2' might not have been initialized">static final int sfi2</error>;
<error descr="Variable 'fi1' might not have been initialized">final int fi1</error>;
<error descr="Variable 'fi2' might not have been initialized">final int fi2</error>;
class inner {
<error descr="Variable 'fii' might not have been initialized">final int fii</error>;
}
final int fi3;
final int fi4;
static final int csfi1 = 0;
static final int csfi2 = csfi1 + 13 / 5;
static final int csfi3;
static {
if (csfi1 < 13) {
csfi3 = csfi2 + (csfi1 == 4 ? 5 : csfi2/13);
}
else {
csfi3 = 0;
sfi2 = 2;
}
}
final int cifi1 = 1;
final int cifi2 = ff();
final int cifi3;
int ff() {
int i = cifi1 + cifi2 + cifi3 + fi3 + fi4;
return i;
}
{
switch (cifi1) {
case 2: cifi3 = 2; break;
case 1: cifi3 = 20; break;
case 0: cifi3 = 21; break;
default: cifi3 = 22; break;
}
}
final int cifi4;
a() {
cifi4 = 4;
int i = <error descr="Variable 'fi3' might not have been initialized">fi3</error>;
fi3 = 3;
a ainst = null;
fi4 = ainst.fi4;
}
a(int i) {
this.cifi4 = i;
fi2 = 3;
fi3 = 3;
a ainst = null;
fi4 = ainst.fi4;
}
a(String s) {
this(0);
int i = fi3;
}
}
class Test {
// access from within inner class OK
final boolean FB;
{
class s {
boolean b = FB;
}
FB = true;
}
private final String text;
public Test() {
new ActionListener() {
public void actionPerformed(ActionEvent e) {
doSomething(text);////
}
};
text = "Hello world";
}
private void doSomething(String value) {
}
}
// multiple initalizers
class c1 {
private final String x;
{
x = "Hello";
}
private final String y;
{
y = x;
}
void f() {
String s = x+y;
}
}
class c2 {
static {
}
private static final int limit;
static {
limit = 5;
}
final String s;
int k = <error descr="Variable 's' might not have been initialized">s</error>.length();
final String c;
int k2 = <error descr="Variable 'c' might not have been initialized">c</error>.length();
{
s = "";
}
public c2() {
c = "";
}
// its ok
int k3 = c.length();
c2(int i) {
this();
}
}
class UninitializedFinal2 {
<error descr="Variable 's' might not have been initialized">private final String s</error>;
UninitializedFinal2(){
try {
}
finally {
}
}
}
class UninitedFinalFied {
<error descr="Variable 'string' might not have been initialized">private final String string</error>;
public UninitedFinalFied() throws IOException {
init();
}
private void init() throws IOException {}
}
class AssertFinalFied {
private final String string;
public AssertFinalFied(boolean b) throws Exception {
assert b;
string = null;
}
}
class a20Exotic {
int n=k=0;
final int k;
final int k2;
int n2 = k==0 ? (k2=9) : (k2=0);
}
public class cX {
final int i;
cX() {
this(1);
int k = i;
}
cX(int d) {
i = d;
}
}
// http://www.intellij.net/tracker/idea/viewSCR?publicId=20097
class Lemma {
public Lemma() {
name.hashCode();
}
private final String name;
{ name = "Andy";
}
}
class correct {
void f() {
final Object o;
o = new Object();
new Object() {
{ o.toString(); }
};
}
}
public class X {
final int i;
X() {
try {
i = 0;
}
finally {
}
}
}
@@ -0,0 +1,7 @@
interface MyCloneable {
//protected method from java.lang.Object is not implicitly declared in interface with no base interfaces
<error descr="'clone()' in 'MyCloneable' clashes with 'clone()' in 'java.lang.Object'; attempting to use incompatible return type">int</error> clone();
<error descr="'toString()' in 'MyCloneable' clashes with 'toString()' in 'java.lang.Object'; attempting to use incompatible return type">int</error> toString();
}
@@ -0,0 +1,55 @@
interface Bar {
void DoBar();
}
abstract class Foo {
public Foo(Bar b) {
}
}
class Inh extends Foo {
public Integer myField = new Integer(0);
public Inh() {
super(new Bar() {
public void DoBar() {
<error descr="Cannot reference 'Inh.this' before supertype constructor has been called">Inh.this</error>.myField.toString();
}
});
class E extends Foo {
E() {
super(new Bar() {
public void DoBar() {
Inh.this.myField.toString();
}
});
}
public void DoBar() {
Inh.this.myField.toString();
}
}
Inh.this.myField.toString();
}
public Inh(Bar b) {
super(b);
}
}
//IDEADEV-14306
class Base {
protected String field;
public Base(final String field, int l) {
this.field = field;
}
}
class Inhertior extends Base {
public Inhertior() {
super("", <error descr="Cannot reference 'Base.field' before supertype constructor has been called">field</error>.length());
}
}
//end of IDEADEV-14306
@@ -0,0 +1,22 @@
class TestSuper {
public static class A {
private String s = "A";
public void foo() {
System.out.println("A::foo");
}
}
public static class B extends A {
public void foo() {
super.foo();
System.out.println("B::foo " + super.s);
System.out.println("B::foo " + ((A) this).s);
}
}
public static void main(String[] args) {
new B().foo();
}
}
@@ -0,0 +1,13 @@
public class X extends Y {}
public class Y {
private static int x = 0;
public static int getX() {
return x;
}
public static void setX(int x) {
X.<error descr="'x' has private access in 'Y'">x</error> = x;
}
}
@@ -0,0 +1,8 @@
class S extends S3 {
String XXX; //should correctly resolve to java.lang.String
}
class S3 {
private class String {
}
}
@@ -0,0 +1,6 @@
class YouAreNotMyType {
String[][] oldLady() {
return new String[][]{<error descr="Incompatible types. Found: 'java.lang.Integer[]', required: 'java.lang.String[]'">new Integer[]{}</error>};
}
}
@@ -0,0 +1,74 @@
// illegal modifier combinations
abstract public class a {
//////////////////// fields ////////////////////////////////
<error descr="Illegal combination of modifiers: 'public' and 'protected'">public</error> static
<error descr="Illegal combination of modifiers: 'protected' and 'public'">protected</error> int f1 = 0;
<error descr="Illegal combination of modifiers: 'public' and 'private'">public</error> volatile
<error descr="Illegal combination of modifiers: 'private' and 'public'">private</error> int f2 = 0;
<error descr="Illegal combination of modifiers: 'protected' and 'private'">protected</error> final
<error descr="Illegal combination of modifiers: 'private' and 'protected'">private</error> int f3 = 0;
<error descr="Illegal combination of modifiers: 'final' and 'volatile'">final</error>
<error descr="Illegal combination of modifiers: 'volatile' and 'final'">volatile</error> private int f4 = 0;
<error descr="Illegal combination of modifiers: 'public' and 'public'">public</error>
<error descr="Illegal combination of modifiers: 'public' and 'public'">public</error>
int f5 = 0;
public static final int cf1 = 0;
static volatile private int cf2;
transient public static final int cf3 = 0;
protected volatile transient int cf4;
private static final int cf5 = 1;
///////////////////// methods ///////////////////////////////////
<error descr="Illegal combination of modifiers: 'abstract' and 'native'">abstract</error>
<error descr="Illegal combination of modifiers: 'native' and 'abstract'">native</error> void m1();
<error descr="Illegal combination of modifiers: 'static' and 'abstract'">static</error> public
<error descr="Illegal combination of modifiers: 'abstract' and 'static'">abstract</error> void m2();
<error descr="Illegal combination of modifiers: 'final' and 'abstract'">final</error>
<error descr="Illegal combination of modifiers: 'abstract' and 'final'">abstract</error> void m3();
<error descr="Illegal combination of modifiers: 'private' and 'public'">private</error> static
<error descr="Illegal combination of modifiers: 'public' and 'private'">public</error> void m4() {}
<error descr="Illegal combination of modifiers: 'protected' and 'private'">protected</error> final
<error descr="Illegal combination of modifiers: 'private' and 'protected'">private</error> void m5() {}
<error descr="Illegal combination of modifiers: 'public' and 'public'">public</error>
<error descr="Illegal combination of modifiers: 'public' and 'public'">public</error> void m6() {};
public abstract void cm1();
protected static synchronized native void cm2();
public static final void cm3() {}
///////////////////////// classes //////////////////////////////////
<error descr="Illegal combination of modifiers: 'final' and 'abstract'">final</error> static strictfp protected
<error descr="Illegal combination of modifiers: 'abstract' and 'final'">abstract</error> class c1 {}
<error descr="Illegal combination of modifiers: 'private' and 'public'">private</error> final
<error descr="Illegal combination of modifiers: 'public' and 'private'">public</error> class c2 {}
<error descr="Illegal combination of modifiers: 'final' and 'final'">final</error>
<error descr="Illegal combination of modifiers: 'final' and 'final'">final</error> class c3 {}
abstract protected static strictfp class cc1 {}
final private static class cc2 {}
class cc3 {}
static class cc4 {}
///////////////////////// locals
void f() {
<error descr="Illegal combination of modifiers: 'final' and 'final'">final</error>
<error descr="Illegal combination of modifiers: 'final' and 'final'">final</error> int loc;
}
}
@@ -0,0 +1,8 @@
class Foo {
int k;
Class c=<error descr="Unknown class: 'k'">k</error>.class;
void f() {
<error descr="Unknown class: 'java.io'">java.io</error> javaio;
}
}
@@ -0,0 +1,18 @@
class s {
void f() {
// illegal type
<error descr="Illegal type: 'void'">void</error>[] va;
<error descr="Illegal type: 'void'">void</error> vv;
class loc {
void f(<error descr="Illegal type: 'void'">void</error> i) {}
}
Object o = new <error descr="Illegal type: 'void'">void</error>[1];
// this is the only valid void usage
Class voidClass = void.class;
}
{
<error descr="Incompatible types. Found: 'void', required: 'java.lang.Object'">Object o = f();</error>
}
}
@@ -0,0 +1,9 @@
class A_I extends B_I{
public A_I() {
super();
new B_I();
}
}
class B_I{
}
@@ -0,0 +1,80 @@
class c {
void f() {
//---- switch --------------------------------------------------------
switch (<error descr="Incompatible types. Found: 'java.lang.String', required: 'byte, char, short or int'">"s"</error>)
{default:}
byte bt = 0;
switch (bt) {
case <error descr="Incompatible types. Found: 'java.lang.String', required: 'byte'">"S"</error>: break;
case <error descr="Incompatible types. Found: 'long', required: 'byte'">10L</error>: break;
case <error descr="Incompatible types. Found: 'boolean', required: 'byte'">true</error>: break;
case <error descr="Incompatible types. Found: 'int', required: 'byte'">0xdfffffff</error>: break;
case <error descr="Incompatible types. Found: 'char', required: 'byte'">'\udede'</error>: break;
case <error descr="Incompatible types. Found: 'int', required: 'byte'">1280</error>: break;
// assignable compatible to byte
case 0: break;
case 'c': break;
case -1: break;
case 127: break;
}
char ch = 'd';
switch (ch) {
case <error descr="Incompatible types. Found: 'java.lang.String', required: 'char'">"S"</error>: break;
case <error descr="Incompatible types. Found: 'long', required: 'char'">10L</error>: break;
case <error descr="Incompatible types. Found: 'boolean', required: 'char'">true</error>: break;
case <error descr="Incompatible types. Found: 'int', required: 'char'">0xafffffff</error>: break;
// assignable compatible to char
case 0: break;
case '\u4567': break;
case 0xffff: break;
case 255: break;
}
switch ('d') {default:}
/// --------- incompatible types inside array initializer ----------
int[] ia = new int[] {
<error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">"String"</error>
, <error descr="Incompatible types. Found: 'double', required: 'int'">3.4</error>
};
String[] sa = { "s",
<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.String'">false</error>
, <error descr="Incompatible types. Found: 'char', required: 'java.lang.String'">'S'</error>
};
String[] vas = null;
Object o = new int[<error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">vas[0]</error>];
int[] weird={<error descr="Illegal initializer for 'int'">{0}</error>};
int[][] arrayInitializers = {{ }};
int[][][] arrayInitializers2 = {{ }, {{}} };
double[][] i2d = {{1}};
char[][] i2c = {{1}};
char foo = 0x0000; /* okay */
char[] bar = { 1,2,3 }; /* still okay */
char[][] baz = { { 1,2,3 } }; /* not okay in 4.5, okay in 4.0.x and for javac */
/// -------- conditional operator
int i8 = <error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">"ff" + true</error> ? 1 : 2;
int i9 = 1==2 ? 1 : <error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">"ff" + true</error>;
i9 = 1==2 ? 3 : <error descr="Incompatible types. Found: 'null', required: 'int'">null</error>;
Object o9 = true ? 0 : <error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">new Object()</error>;
final char ccons='0';
short ssss=ccons;
byte bbbbbb=ccons;
// too big char to fit in short
final char bigchar='\uffff';
<error descr="Incompatible types. Found: 'char', required: 'short'">short sbig = bigchar;</error>
}
void g(boolean f, byte b) {
byte c = '\n';
<error descr="Incompatible types. Found: 'int', required: 'byte'">byte next = f ? b : '\n';</error>
}
}
@@ -0,0 +1,10 @@
// inherit from final
public class a extends <error descr="Cannot inherit from final 'ff'">ff</error> {
void f() {
Object o = new <error descr="Cannot inherit from final 'ff'">ff</error>() { void gg(){} };
}
}
final class ff {
}
@@ -0,0 +1,134 @@
/// initalizers completion
import java.io.*;
import java.net.*;
public class a {
<error descr="Initializer must be able to complete normally">{
throw new RuntimeException();
}</error>
static <error descr="Initializer must be able to complete normally">{
try {
throw new RuntimeException();
}
finally {
throw new NullPointerException();
}
}</error>
}
class a2 {
{
if (1==2) <error descr="Unhandled exception: java.io.IOException">throw new IOException();</error>
}
<error descr="Unhandled exception: java.io.IOException">a2()</error> {}
}
class a3 {
{
if (1==2) <error descr="Unhandled exception: java.net.SocketException">throw new SocketException();</error>
}
<error descr="Unhandled exception: java.net.SocketException">a3() throws ConnectException</error> {}
}
class b {
{ if (1==2) throw new SocketException(); }
b() throws IOException {}
}
class a4 {
{
if (true) {
throw new Exception();
}
}
a4() throws Exception {
}
}
class a5 {
int i = <error descr="Unhandled exception: java.lang.ClassNotFoundException">f();</error>
int f() throws ClassNotFoundException {
return 0;
}
}
class a6 {
int i = f();
int f() throws ClassNotFoundException {
return 0;
}
a6() throws ClassNotFoundException {
}
}
class a7 {
<error descr="Initializer must be able to complete normally">{
try {
throw new RuntimeException();
} finally {
}
}</error>
}
class MyRuntimeException extends RuntimeException {}
class GUIBase {
GUIBase () throws MyRuntimeException {}
}
class GUI extends GUIBase {
}
class a8 {
{
assert true;
}
{
assert false;
}
}
class a9 {
private static interface AnInterface {}
public AnInterface getAnInterface() {
return new AnInterface() {
{
<error descr="Unhandled exception: java.io.FileNotFoundException">new java.io.FileInputStream("somefile")</error>;
}
};
}
}
////////////////////////////////
class BadStatic {
static String f() throws ClassNotFoundException {
return null;
}
private static final String FOO = <error descr="Unhandled exception: java.lang.ClassNotFoundException">f();</error>
public BadStatic() throws ClassNotFoundException {
}
}
class H {
public H() throws FileNotFoundException {
}
static {
if(true) {
<error descr="Unhandled exception: java.io.FileNotFoundException">throw new FileNotFoundException();</error>
}
}
}
@@ -0,0 +1,5 @@
<x <warning descr="AAATTR">aaa="dddd"</warning>>
<l>
<warning desr="ENTITY">&nbsp;</warning>
</l>
</x>
@@ -0,0 +1,37 @@
// instantiate abstract
public class a {
void f() {
new <error descr="'ii' is abstract; cannot be instantiated">ii</error>();
new <error descr="'c1' is abstract; cannot be instantiated">c1</error>();
new <error descr="Class 'Anonymous class derived from c1' must either be declared abstract or implement abstract method 'f1(int)' in 'c1'">c1</error>() {
public void f2() {}
};
new <error descr="Class 'Anonymous class derived from c1' must either be declared abstract or implement abstract method 'f1(int)' in 'c1'">c1</error>() {
public void f1() {}
};
new <error descr="Class 'Anonymous class derived from c1' must either be declared abstract or implement abstract method 'f2()' in 'Anonymous class derived from c1'">c1</error>() {
public void f1(int i) {}
public <error descr="Abstract method in non-abstract class">abstract</error> void f2();
};
new c1() {
public void f1(int i) {}
};
new ii() { public void f1(){} public void f2(){} };
}
}
abstract class c1 {
abstract public void f1(int i);
}
interface ii {
abstract void f1();
void f2();
}
@@ -0,0 +1,20 @@
interface i <error descr="No implements clause allowed for interface">implements Runnable</error> {}
interface ii {}
class cs extends <error descr="No interface expected here">ii</error> {}
interface is extends ii {}
class cs2 implements <error descr="Interface expected here">cs</error> {}
interface is3 extends <error descr="Interface expected here">cs</error> {}
abstract class Exercis {
public static void main() {
Object o = <error descr="Class name expected here">java.lang</error>.this;
new Runnable() {
public void run() {
<error descr="No interface expected here">Runnable</error>.this.run(); ///
}
};
}
}
@@ -0,0 +1,104 @@
// invalid expressions
public class a12 {
static int i;
int f(int i) {
<error descr="Not a statement">1;</error>
<error descr="Not a statement">1==2;</error>
<error descr="Not a statement">1==2 ? 1 : 3;</error>
<error descr="Not a statement">f(1) == 3;</error>
<error descr="Not a statement">1,2;</error>
<error descr="Not a statement">~1;</error>
<error descr="Not a statement">!(1==2);</error>
<error descr="Not a statement">new int[0];</error>
<error descr="Not a statement">new a12[10];</error>
<error descr="Not a statement">new a12[]{};</error>
<error descr="Not a statement">new int[]{1};</error>
<error descr="Not a statement">new String[]{new String()};</error>
if (i==1)
<error descr="Not a statement">String s00 = "";</error>
for (;;)
<error descr="Not a statement">String s01 = "";</error>
for (<error descr="Not a statement">1==2,i=3;</error> i<3; <error descr="Not a statement">!(1==2)</error>);
label2:
<error descr="Not a statement">int ksdfgdf;</error>
int i1=3, g=5;
g++;
++g;
for (int k=1,l=3; k<3; k++,l--) {;};
class s {}
new s() { void f(){}};
return 3;
}
//////////////////////////
void f() {
a12 a[] = new a12[4];
int[] ai = null;
<error descr="Variable expected">5</error> = 5;
<error descr="Variable expected">5</error>++;
++<error descr="Variable expected">5</error>;
<error descr="Variable expected">5</error> += 5;
foo123Unresolved(<error descr="Expression expected">String</error>);
foo123Unresolved(<error descr="Cannot resolve symbol 'xxxx'">xxxx</error>);
// incomplete code should not cause 'expr expected'
Object<error descr="';' expected"> </error>
<error descr="Array type expected; found: 'int'">4</error>[1] = 5;
a[<error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">"d"</error>] = null;
<error descr="Array type expected; found: 'a12'">a[0]</error>[1] = 5;
<error descr="Array type expected; found: 'int'">i</error>[0] = 5;
i = ai[<error descr="Incompatible types. Found: 'a12', required: 'int'">a[1]</error>];
final a12[] a12a = new a12[<error descr="Incompatible types. Found: 'null', required: 'int'">{null}</error>];
int[] iarr = new int[<error descr="Incompatible types. Found: 'null', required: 'int'">{0}</error>];
new String[<error descr="Incompatible types. Found: 'java.lang.String', required: 'int'">"d"</error>];
new String[<error descr="Incompatible types. Found: 'double', required: 'int'">1.1</error>]
[<error descr="Incompatible types. Found: 'a12', required: 'int'">this</error>];
a[0] = null;
(a)[(1)].i = 3;
(( i) ) = (5);
a12.i = 0;
arr()[0] = 1;
new int[] { 1,3} [0] = 2;
Object[] var = null;
i = var.length;
// array initializers
var = <error descr="Expression expected">{ null, null }</error>;
Object var1 = <error descr="Expression expected">{ null, null }</error>;
int[] var2 = { 1,2 };
var2 = new int[] { 2, 4};
int[][] ii2 = { { 1,2}, {4} };
}
<error descr="Illegal type: 'void'">void</error>[] fv() {
if (1==2) return new <error descr="Illegal type: 'void'">void</error>[0];
return null;
}
int[] arr() { return new int[0]; }
public <error descr="Invalid method declaration; return type required">foo</error>() {
}
// do not warn about illegal type in incomplete declarations (http://www.intellij.net/tracker/idea/viewSCR?publicId=9586)
void foo<EOLError descr="';' expected"></EOLError>
}
@@ -0,0 +1,39 @@
class a {
/**period.
* @return x
*/
int f() {
return 0;
}
/**period.
* @return <tt>x</tt> wtf ?
*/
int f2() {
return 0;
}
/**period.
* @return
* true if someone wants
*/
int f3() {
return 0;
}
/**period.
* @param i description goes here
* <warning>@return</warning>
*/
int f(int i) {
return i;
}
/**
* @see localVar
*/
static String KEY_FOR_VAR="index.localVar";
String localVar;
}
@@ -0,0 +1,418 @@
import java.io.*;
import java.net.*;
import java.util.*;
public class a {
static final a ai;
int ii;
static {
<error descr="Variable 'ai' might not have been initialized">ai</error>.ii = 4;
ai = null;
}
void f1(int i) {
int j;
i = <error descr="Variable 'j' might not have been initialized">j</error>;
}
void f2(int i) {
int j;
if (i ==2) j = 4;
i = <error descr="Variable 'j' might not have been initialized">j</error>;
}
void f3(int i) {
int j;
if (i==3 && (j=i) != 9) {
i = j+2;
}
else {
i -= -1 - <error descr="Variable 'j' might not have been initialized">j</error>;
}
}
void f4(int i) {
final int dd;
Runnable r = new Runnable() {
public void run() {
int j = <error descr="Variable 'dd' might not have been initialized">dd</error>;
}
};
if (i == 3) dd = 5;
else dd = 6;
}
void f5(int i) {
final int k;
class inner {
void f() {
int j = <error descr="Variable 'k' might not have been initialized">k</error>;
}
}
}
void f6(int a){
Object[] var;
if (a > 0){
}
else{
var = new Object[1];
}
System.out.println(<error descr="Variable 'var' might not have been initialized">var</error>);
}
void f7() {
int k;
try {
k=0;
} finally {
if (<error descr="Variable 'k' might not have been initialized">k</error>==0) {
}
}
}
void f8(int n)
{
int k;
while (n < 4) {
k = n;
break;
}
// k is not "definitely assigned" before this
System.out.println(<error descr="Variable 'k' might not have been initialized">k</error>);
}
void f9() {
final int k;
<error descr="Variable 'k' might not have been initialized">k</error>+=1;
}
void f10() {
final int k;
<error descr="Variable 'k' might not have been initialized">k</error>++;
int i = <error descr="Variable 'i' might not have been initialized">i</error> + 1;
int j = (j=2) == 1 || j==0 ? 1 : j;
}
void f11() {
int x = 0;
switch (x) {
case 0:
int y = 1;
System.out.println(y);
break;
case 1:
int z = <error descr="Variable 'y' might not have been initialized">y</error>;
System.out.println(z);
break;
}
}
void f12() {
switch (0) {
case 0:
int k=0;
case 1:
System.out.println(<error descr="Variable 'k' might not have been initialized">k</error>);
}
}
public class AInner {
class AI2 {}
private AI2 myTitleRenderer = new AI2() {
private String myLabel = "";
public String getTreeCellRendererComponent(String value) {
if (value instanceof String) {
int i = myLabel.length();
}
return null;
}
};
}
void f13() {
int i ;
try {
i = 0;
if (i==0) throw new IOException();
}
catch (IOException e) {
if (<error descr="Variable 'i' might not have been initialized">i</error>==0) return;
}
}
abstract class X {
class XException extends Exception{}
class YException extends Exception{}
class ZException extends Exception{}
public void test() throws XException {
final Object obj;
try {
obj = test1();
}
catch (YException fnf) {
}
finally {
try {
test2();
}
catch (ZException eof) {
}
}
<error descr="Variable 'obj' might not have been initialized">obj</error>.hashCode(); //can stay uninitialized
}
public abstract Object test1() throws YException, XException;
public abstract void test2() throws XException, ZException;
}
public static int test(List aList) {
List list2;
int counter = 0;
for (int i=0; i<aList.size(); i++) {
while (counter != 0) {
counter++;
list2 = new ArrayList();
}
<error descr="Variable 'list2' might not have been initialized">list2</error>.add(aList.get(i));
}
return counter;
}
void forEachParam(java.io.File x) {
for (java.io.File f: <error descr="Variable 'f' might not have been initialized">f</error>.listFiles()) {
forEachParam(f);
}
}
// all code below is correct
int cf1(int i) {
return i;
}
void cf2(int i) {
int j;
if (i == 0 && (j=i) != 2) {
i = j;
}
if (i == 0 || (j=i) != 2 || j>3) {
i = 2;
}
}
boolean cf3(int i) {
final int j;
if (i<3 || i>33) j = i;
else j = 4;
i = j;
return i==3 && i==5;
}
void cf33(int i) {
final int j2;
while (true) {
j2 = 5;
break;
}
i = j2;
}
void cf4() {
final int i1;
int i2;
final Object o1;
}
void cf5() {
final int dialog = 3;
final int dd;
if (dialog == 3) dd = 5;
else dd = 6;
Runnable r = new Runnable() {
public void run() {
int i = dialog;
int j = dd;
}
};
}
void cf6() {
class inner extends a {
void fi() {
int i = ii;
}
}
a ainst = new a() {
void fi() {
int i = ii;
}
};
}
a() {
int i = ai.ii;
}
void cf7() {
for(int i = 0; i < 3; i++){
Object element;
if (i==0){
element = null;
}
else if (i==3){
element = null;
}
else{
continue;
}
Object newe = element;
}
}
void cf8(int n)
{
int i;
while (true) {
if (false) {
i = 0;
break;
}
}
i++;
}
final boolean FB = true;
void cf9() {
int k;
if (FB) {
k = 4;
}
int j = k;
}
void cf10() {
for (String line; (line = "") != null; ) {
line.indexOf(" ");
}
}
void cf11(boolean d) {
boolean b;
boolean c = true;
if (c && (false && true)) {
c = b;
}
}
void cf12() {
boolean booleanVar = true;
boolean stringVar;
if (!(booleanVar && (stringVar = true))) {
stringVar = false;
}
if (stringVar) {
}
}
void cfxx(boolean a, boolean b) {
int n;
if ((a || b) && (n = 0) >= 2) {
n++; //
}
}
void cfxx1(boolean a, int b) {
final int i;
if ((true || false) && (i = b) != 0) {
System.out.println(i); // i gets highlighted }
}
}
void cfx3() {
boolean b;
boolean c;// = true;
if (c && false) {
c = b;
}
}
void cfx4()
{
final int k;
if (false) {
k = 0;
k = 1;
System.out.println(k);
}
}
}
class Main {
void f() {
final int x;
x = 0;
class C {
void m () {
int y = x;
}
}
}
}
// continue in finally
class QuartzSchedulerThread {
public void run() throws IOException {
while (true) {
try {
} finally {
try {
run();
} catch (IOException e) {
e.printStackTrace();
}
continue;
}
}
}
}
class ExceptionProblems {
private boolean bad() {
final boolean succeeded;
try {
new FileInputStream("test");
succeeded = true;
} catch (IOException e) {
<error descr="Variable 'succeeded' might already have been assigned to">succeeded</error> = false; // should warn here
}
return succeeded;
}
}
class ImGood {
int foo() { //IDEADEV-7446
int foo;
if (true) {
foo = 42;
}
return foo;
}
}
class SwitchTest
{
public static String method()
{
int a = 0;
switch (a)
{
case 0:
return null;
case 4:
String description;
return <error descr="Variable 'description' might not have been initialized">description</error>;
default:
return "";
}
}
}
@@ -0,0 +1,67 @@
// continue outside of.../loop label
public class a {
void f() {
<error descr="Continue outside of loop">continue;</error>
while (true) {
continue;
}
do { continue; } while (true);
switch (1) {
case 1: <error descr="Continue outside of loop">continue;</error>
}
for (;;) {
continue;
}
for (;;) {
new ff() {
void f() {
<error descr="Continue outside of loop">continue;</error>
}
};
continue;
}
while (true) {
class s {
{
<error descr="Continue outside of loop">continue;</error>
}
}
continue;
}
do {
class s {
{
<error descr="Continue outside of loop">continue;</error>
}
}
continue;
} while (true);
a:
if (2==4) {
for (;;) {
<error descr="Not a loop label: 'a'">continue a;</error>
}
}
a:
b:
for (;;) {
<error descr="Not a loop label: 'a'">continue a;</error>
}
}
}
class ff {
}
@@ -0,0 +1,104 @@
// illegal method calls
class A {
private class B {
Object o = super<error descr="'.' expected">;</error>
}
private B b = null;
A(A a)
{
new A(a).new B();
B b = new A(a).b;
AA aa = (AA) a;
AA.SAA saa = aa.new SAA();
AA.SAA saa1 = <error descr="'AA' is not an enclosing class">new AA.SAA()</error>;
}
}
class AA extends A {
private AA aa;
AA(A a) {
super(a);
}
class SAA {}
void f() {
new AA.SAA();
new SAA();
AA.this.aa.new SAA();
class MyAA extends AA {
public MyAA(A a) {
super(a);
}
}
}
}
class AX {
class B {
}
}
class CX {
{
<error descr="'AX' is not an enclosing class">new AX.B()</error>;
}
}
class c {
c() {
}
class inner {
class ininner {}
}
static void f() {
<error descr="'c.this' cannot be referenced from a static context">new inner()</error>;
}
static {
<error descr="'c.this' cannot be referenced from a static context">new inner()</error>;
}
}
class A1 {
void f() {}
}
class B1 {
void f() {
A1.<error descr="Non-static method 'f()' cannot be referenced from a static context">f</error>();
}
}
class AAAA implements java.io.Serializable
{
public AAAA ()
{
super(); // here
}
}
class DCC {
public DCC(int i) {
}
public DCC(int i, int z) {
<error descr="Method call expected">DCC(i)</error>;
}
void f() {
<error descr="Method call expected">DCC(1)</error>;
new DCC(1);
}
}
class ThisExpression {
static String foo() {
System.out.println(<error descr="'ThisExpression.this' cannot be referenced from a static context">this</error>);
return <error descr="'ThisExpression.this' cannot be referenced from a static context">this</error>.toString();
}
}
@@ -0,0 +1,7 @@
class A {{
String.valueOf(<error descr="Cannot resolve symbol 'chars'">chars</error>, 0, 10); // all arguments are highlighted when only chars has a problemij
new String(<error descr="Cannot resolve symbol 'chars'">chars</error>, 0, 10); // highlighting is good here.
String.valueOf<error descr="'valueOf(char[], int, int)' in 'java.lang.String' cannot be applied to '(int, int, int)'">(0, 0, 10)</error>;
new String<error descr="Cannot resolve constructor 'String(int, int, int)'">(0, 0, 10)</error>;
}}
@@ -0,0 +1,68 @@
// not allowed modifiers
<error descr="Modifier 'private' not allowed here">private</error>
<error descr="Modifier 'static' not allowed here">static</error>
<error descr="Modifier 'volatile' not allowed here">volatile</error>
class a {
static
<error descr="Modifier 'private' not allowed here">private</error>
<error descr="Modifier 'public' not allowed here">public</error>
<error descr="Modifier 'abstract' not allowed here">abstract</error> {
int i = 4;
}
<error descr="Modifier 'synchronized' not allowed here">synchronized</error> Object x;
private class c1 {
private void ff() {}
}
static strictfp class c2 {}
private static interface ii {
<error descr="Modifier 'private' not allowed here">private</error> int f1 = 2;
<error descr="Modifier 'protected' not allowed here">protected</error> int f2 = 2;
public int f3 = 3;
<error descr="Modifier 'private' not allowed here">private</error> int f1();
<error descr="Modifier 'protected' not allowed here">protected</error> int f2();
public int f3();
void f4();
}
void f1(final String i) {
final int ii = 3;
<error descr="Modifier 'private' not allowed here">private</error> int i2;
<error descr="Modifier 'static' not allowed here">static</error> int i3;
try {
throw new Exception();
} catch (final <error descr="Modifier 'static' not allowed here">static</error> Exception e) {
}
}
}
interface ff {
static class cc {}
}
abstract class c {
<error descr="Modifier 'abstract' not allowed here">abstract</error> c();
<error descr="Modifier 'static' not allowed here">static</error> c(int i) {}
<error descr="Modifier 'native' not allowed here">native</error> c(boolean b);
<error descr="Modifier 'final' not allowed here">final</error> c(char c) {}
<error descr="Modifier 'strictfp' not allowed here">strictfp</error> c(String s) {}
<error descr="Modifier 'synchronized' not allowed here">synchronized</error> c(Object o) {}
}
interface i3 {
<error descr="Modifier 'strictfp' not allowed here">strictfp</error> int f1;
<error descr="Modifier 'transient' not allowed here">transient</error> int f2;
<error descr="Modifier 'synchronized' not allowed here">synchronized</error> int f3;
<error descr="Modifier 'strictfp' not allowed here">strictfp</error> int m1() { return 0; }
<error descr="Modifier 'transient' not allowed here">transient</error> int m2() { return 0; }
<error descr="Modifier 'synchronized' not allowed here">synchronized</error> int m3() { return 0; }
}
@@ -0,0 +1,20 @@
class c {
void f() {
Object o = null;
if (<error descr="Incompatible types. Found: 'java.lang.Object', required: 'boolean'">o</error>) {
return;
}
String str1 = "";
String str2 = "";
do {}
while (<error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">str1 = str2</error>);
int i8 = <error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">"ff" + true</error> ? 1 : 2;
assert <error descr="Incompatible types. Found: 'int', required: 'boolean'">0</error>;
assert <error descr="Incompatible types. Found: 'char', required: 'boolean'">'a'</error>;
assert <error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">""</error>;
assert <error descr="Incompatible types. Found: 'void', required: 'boolean'">f()</error>;
}
}
@@ -0,0 +1,12 @@
class m {
int i;
void f() {
int r = 0;
new Runnable() {
public void run() {
int k = <error descr="Variable 'r' is accessed from within inner class. Needs to be declared final.">r</error>;
int ii = i;
}
};
}
}
@@ -0,0 +1,46 @@
class c {
void f1() {
try {
} catch (<error descr="Incompatible types. Found: 'java.lang.Error[]', required: 'java.lang.Throwable'">Error[] e</error>) {
}
try {
} catch (<error descr="Incompatible types. Found: 'java.lang.Error[]', required: 'java.lang.Throwable'">Error e[]</error>) {
}
try {
} catch (<error descr="Incompatible types. Found: 'java.lang.Error[][][][]', required: 'java.lang.Throwable'">Error[] []e[] []</error>) {
}
catch(<error descr="Incompatible types. Found: 'int', required: 'java.lang.Throwable'">int e</error>) {
}
}
}
class MyException // does not extend Throwable
{}
class a60
{
public void test() throws <error descr="Incompatible types. Found: 'MyException', required: 'java.lang.Throwable'">MyException</error>
{
throw <error descr="Incompatible types. Found: 'MyException', required: 'java.lang.Throwable'">new MyException()</error>;
}
public void test(int i) {
switch (i) {
case 1: throw <error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Throwable'">false</error>;
case 2: throw <error descr="Incompatible types. Found: 'int', required: 'java.lang.Throwable'">1</error>;
case 3: throw <error descr="Incompatible types. Found: 'double', required: 'java.lang.Throwable'">1.0</error>;
case 4: throw <error descr="Incompatible types. Found: 'char', required: 'java.lang.Throwable'">'a'</error>;
case 5: throw <error descr="Incompatible types. Found: 'long', required: 'java.lang.Throwable'">1L</error>;
case 6: throw <error descr="Incompatible types. Found: 'float', required: 'java.lang.Throwable'">1.0f</error>;
}
}
}
class Contest {
short midget;
void strongMan() throws <error descr="Class name expected">midget</error> {
}
}
@@ -0,0 +1,59 @@
import <info descr="null" type="CLASS_NAME">java.io</info>.*; // highlight on demand import as class name
class <info descr="null" type="CLASS_NAME">a</info> {
void <info descr="null" type="METHOD_DECLARATION">method</info>() {
<info descr="null" type="METHOD_CALL">method</info>();
new <info descr="null" type="CONSTRUCTOR_CALL">Exception</info>();
new <info descr="null" type="CONSTRUCTOR_CALL">java.lang.Exception</info>();
}
<info descr="null" type="CONSTRUCTOR_DECLARATION">a</info>() {
new <info descr="null" type="CONSTRUCTOR_CALL">a</info>();
}
/**
* @see <info descr="null" type="INTERFACE_NAME">itf</info>#<info descr="null" type="METHOD_CALL">method</info>(<info descr="null" type="JAVA_KEYWORD">double</info>)
*/
static void <info descr="null" type="METHOD_DECLARATION">f</info>() {
<info descr="null" type="CLASS_NAME">Integer</info>.<info descr="null" type="STATIC_METHOD">parseInt</info>("");
<info descr="null" type="CLASS_NAME">java.lang.Integer</info>.<info descr="null" type="STATIC_METHOD">parseInt</info>("");
<info descr="null" type="STATIC_METHOD">f</info>();
}
interface <info descr="null" type="INTERFACE_NAME">itf</info>{
int <info descr="null" type="STATIC_FIELD">CONST</info> = 0;
/** .
* @param <info descr="null" type="PARAMETER">d</info> Important param
*/
void <info descr="null" type="METHOD_DECLARATION">method</info>(double <info descr="null" type="PARAMETER">d</info>);
}
void <info descr="null" type="METHOD_DECLARATION">ff</info>(<info descr="null" type="INTERFACE_NAME">Runnable</info> <info descr="null" type="PARAMETER">r</info>) {
<info descr="null" type="METHOD_CALL">ff</info>(
new <info descr="null" type="INTERFACE_NAME">java.lang.Runnable</info>()
{
public void <info descr="null" type="METHOD_DECLARATION">run</info>() {}
int <info descr="null" type="INSTANCE_FIELD">instance</info> = 0;
}
);
int <info descr="null" type="LOCAL_VARIABLE">i</info> = <info descr="null" type="CLASS_NAME">java.lang.Integer</info>.<info descr="null" type="STATIC_FIELD">MIN_VALUE</info>;
int <info descr="null" type="LOCAL_VARIABLE">j</info> = <info descr="null" type="INTERFACE_NAME">itf</info>.<info descr="null" type="STATIC_FIELD">CONST</info>;
}
}
class <info descr="null" type="CLASS_NAME">NoCtrClass</info> {
{
// default constructor call looks like class
new <info descr="null" type="CLASS_NAME">NoCtrClass</info>();
}
void <info descr="null" type="METHOD_DECLARATION">ff</info>(int <info descr="null" type="REASSIGNED_PARAMETER">param</info>) {
int <info descr="null" type="REASSIGNED_LOCAL_VARIABLE">i</info> = 1;
<info descr="null" type="REASSIGNED_LOCAL_VARIABLE">i</info> ++;
<info descr="null" type="REASSIGNED_PARAMETER">param</info> = 0;
}
}
class <info descr="null" type="CLASS_NAME">Generic</info><<info descr="null" type="TYPE_PARAMETER_NAME">TT</info> extends <info descr="null" type="INTERFACE_NAME">Runnable</info>> {
<info descr="null" type="TYPE_PARAMETER_NAME">TT</info> <info descr="null" type="INSTANCE_FIELD">field</info>;
}
@@ -0,0 +1,64 @@
/// assignment compatible types
import java.io.*;
import java.net.*;
public class a {
final int FI = 2;
final int FIBIG = 200000000;
void f() {
int i1=-<error descr="Integer number too large">2147483649</error>;
int i2=<error descr="Integer number too large">2147483648</error>;
int i3 = -2147483648;
int i4 = -0x7fffffff;
int i5 = -017777777777;
int i6 = <error descr="Hexadecimal numbers must contain at least one hexadecimal digit">0x</error>;
int i7 = 0xdeadbeef;
int i8 = 0xffffffff;
int i9=<error descr="Integer number too large">0xffffffff9</error>;
int i10= 0x80000000;
int i11=0000000000000+0x000000000;
int i12=0x00000000000000000000000;
int i13= <error descr="Integer number too large">040000000000</error>;
int i14= 020000000000;
int i15 = <error descr="Integer number too large">0xf044332211</error>;
int octale = 017777777777; // negative
long l1=-<error descr="Long number too large">9223372036854775809L</error>;
long l2=<error descr="Long number too large">9223372036854775808L</error>;
long l3=-9223372036854775808L;
long l4=-<error descr="Integer number too large">2147483649</error>;
long l5=<error descr="Integer number too large">2147483648</error>;
long l6 = <error descr="Hexadecimal numbers must contain at least one hexadecimal digit">0xL</error>;
long l7= 0xdeadbeefffffffffL;
long l8= 0xffffffffffffffffL;
long l9=<error descr="Long number too large">0xffffffffffffffff9L</error>;
long l10=0x8000000000000000L;
long octalValue = 01777777777777777777600L;
long octalValua = 01777777777777777777777L;
float f1= <error descr="Floating point number too small">1e-46f</error>;
float f2=<error descr="Floating point number too large">1e39f</error>;
float f3=0E1F;
double dd1=<error descr="Floating point number too small">1e-324</error>;
double dd2=<error descr="Floating point number too large">1e309</error>;
double dd3=0E1;
double d1=<error descr="Malformed floating point literal">1.E</error>;
double d2=<error descr="Malformed floating point literal">1.e</error>;
double d3=<error descr="Malformed floating point literal">1.E+</error>;
double d4=<error descr="Malformed floating point literal">1.E-</error>;
double d5=<error descr="Malformed floating point literal">.1eD</error>;
double d6=<error descr="Malformed floating point literal">.1e+D</error>;
double d7=<error descr="Malformed floating point literal">1e+D</error>;
double d8=<error descr="Malformed floating point literal">1e-D</error>;
double d9=<error descr="Malformed floating point literal">1e-d</error>;
double d10=<error descr="Malformed floating point literal">1e-F</error>;
double d11=<error descr="Malformed floating point literal">1e-f</error>;
}
}
@@ -0,0 +1,88 @@
// overflows in const expressions
class c {
// @*#$& ! references do not work in JRE
static final long LONG_MIN_VALUE = 0x8000000000000000L;
static final long LONG_MAX_VALUE = 0x7fffffffffffffffL;
static final int INTEGER_MIN_VALUE = 0x80000000;
static final int INTEGER_MAX_VALUE = 0x7fffffff;
static final float FLOAT_MIN_VALUE = 1.4e-45f;
static final float FLOAT_MAX_VALUE = 3.4028235e+38f;
static final double DOUBLE_MIN_VALUE = 4.9e-324;
static final double DOUBLE_MAX_VALUE = 1.7976931348623157e+308;
void f() {
float f1 = <warning descr="Numeric overflow in expression">1.0f / 0.0f</warning>;
f1 = <warning descr="Numeric overflow in expression">FLOAT_MAX_VALUE + FLOAT_MAX_VALUE</warning>;
f1 = <warning descr="Numeric overflow in expression">FLOAT_MAX_VALUE * 2</warning>;
f1 = <warning descr="Numeric overflow in expression">2 / FLOAT_MIN_VALUE</warning>;
f1 = FLOAT_MIN_VALUE + 1;
f1 = - FLOAT_MIN_VALUE;
f1 = -FLOAT_MAX_VALUE;
System.out.println(f1);
double d1 = <warning descr="Numeric overflow in expression">DOUBLE_MAX_VALUE - -DOUBLE_MAX_VALUE</warning>;
d1 = DOUBLE_MAX_VALUE + 1;
d1 = <warning descr="Numeric overflow in expression">2 * DOUBLE_MAX_VALUE</warning>;
d1 = <warning descr="Numeric overflow in expression">2 / DOUBLE_MIN_VALUE</warning>;
d1 = <warning descr="Numeric overflow in expression">2 / 0.0d</warning>;
d1 = <warning descr="Numeric overflow in expression">2 / 0.0</warning>;
System.out.println(d1);
int i1 = <warning descr="Numeric overflow in expression">INTEGER_MAX_VALUE + 1</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MAX_VALUE - 1 + 2</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MAX_VALUE - INTEGER_MIN_VALUE</warning>;
i1 = <warning descr="Numeric overflow in expression">-INTEGER_MIN_VALUE</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MIN_VALUE - 1</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MIN_VALUE - INTEGER_MAX_VALUE</warning>;
i1 = INTEGER_MIN_VALUE + INTEGER_MAX_VALUE;
i1 = - INTEGER_MAX_VALUE;
i1 = - -INTEGER_MAX_VALUE;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MIN_VALUE * -1</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MIN_VALUE * 2</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MAX_VALUE * -2</warning>;
i1 = INTEGER_MAX_VALUE * -1;
i1 = <warning descr="Numeric overflow in expression">2 / 0</warning>;
i1 = <warning descr="Numeric overflow in expression">INTEGER_MIN_VALUE / -1</warning>;
System.out.println(i1);
long l1 = <warning descr="Numeric overflow in expression">LONG_MAX_VALUE + 1</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MAX_VALUE - 1 + 2</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MAX_VALUE - LONG_MIN_VALUE</warning>;
l1 = <warning descr="Numeric overflow in expression">-LONG_MIN_VALUE</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MIN_VALUE - 1</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MIN_VALUE - LONG_MAX_VALUE</warning>;
l1 = LONG_MIN_VALUE + LONG_MAX_VALUE;
l1 = - LONG_MAX_VALUE;
l1 = - -LONG_MAX_VALUE;
l1 = <warning descr="Numeric overflow in expression">-INTEGER_MIN_VALUE</warning>;
l1 = -1L + INTEGER_MIN_VALUE;
l1 = <warning descr="Numeric overflow in expression">LONG_MIN_VALUE * INTEGER_MIN_VALUE</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MIN_VALUE * -1</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MIN_VALUE * 2</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MAX_VALUE * -2</warning>;
l1 = INTEGER_MIN_VALUE * -1L;
l1 = <warning descr="Numeric overflow in expression">2 / 0L</warning>;
l1 = <warning descr="Numeric overflow in expression">2 % 0L</warning>;
l1 = <warning descr="Numeric overflow in expression">LONG_MIN_VALUE / -1</warning>;
l1 = <warning descr="Numeric overflow in expression">30 * 24 * 60 * 60 * 1000</warning>;
l1 = <warning descr="Numeric overflow in expression">30000000 * 243232323</warning>
* (<warning descr="Numeric overflow in expression">LONG_MAX_VALUE +3</warning>) / 5;
System.out.println(l1);
}
private static final long MILLIS_PER_DAY = 24 * 3600 * 1000;
private static final long _7DAYS = 7 * MILLIS_PER_DAY;
private static final long _30DAYS = 30 * MILLIS_PER_DAY;
private static final long _1000DAYS = 1000 * MILLIS_PER_DAY;
{
System.out.println(_1000DAYS + _30DAYS + _7DAYS);
}
int iii = <warning descr="Numeric overflow in expression">2 % 0</warning>;
}
@@ -0,0 +1,70 @@
// operators applicability
public class a {
int f(int ik) {
if (<error descr="Operator '<' cannot be applied to 'int','null'">1 < null</error>) {}
if (<error descr="Operator '==' cannot be applied to 'null','char'">null == 'c'</error>) {}
Object o = null;
if (<error descr="Operator '>=' cannot be applied to 'double','java.lang.Object'">1.2 >= o</error>) {}
if (<error descr="Operator '!=' cannot be applied to 'long','java.lang.String'">1L != "null"</error>) {}
if (<error descr="Operator '==' cannot be applied to 'boolean','int'">(1==2) == 3</error>) {}
int i = (<error descr="Operator '+' cannot be applied to 'int','null'">1 + null</error>);
i = <error descr="Operator '/' cannot be applied to 'java.lang.Object','java.lang.Object'">o/o</error>;
i = <error descr="Operator '-' cannot be applied to 'null','double'">null - 1.2</error>;
i = <error descr="Operator '%' cannot be applied to 'boolean','int'">true % 4</error>;
i = <error descr="Operator '<<' cannot be applied to 'int','java.lang.Object'">i << o</error>;
i = <error descr="Operator '>>' cannot be applied to 'boolean','null'">(i==2) >> null</error>;
i = <error descr="Operator '>>>' cannot be applied to 'int','double'">i >>> 2.2</error>;
i = <error descr="Operator '&' cannot be applied to 'int','java.lang.Object'">i & o</error>;
i = <error descr="Operator '|' cannot be applied to 'boolean','double'">true | 2.1</error>;
i = <error descr="Operator '&&' cannot be applied to 'int','int'">2 && 3</error>;
i = <error descr="Operator '||' cannot be applied to 'double','long'">3.8 || 2L</error>;
i = <error descr="Operator '||' cannot be applied to 'null','java.lang.Object'">null || o</error>;
<error descr="Operator '|' cannot be applied to 'int','null'">i |= null</error>;
double d = 0;
<error descr="Operator '&' cannot be applied to 'double','int'">d &= i</error>;
<error descr="Operator '/' cannot be applied to 'java.lang.Object','int'">o /= 3</error>;
String sss2 = <error descr="Operator '+' cannot be applied to 'java.lang.String','void'">"" + fvoid()</error>;
int sss1 = <error descr="Operator '+' cannot be applied to 'void','int'">fvoid() + 2</error>;
int ia[] = null;
boolean b = 1==3 || 3 < '4' && (1>3.5) == (o == null) || false || (o == "d");
b = (1 != 'f') == (3.4 >= 'x') && o!=null & (b | (3<4));
i = i & 2 | i>>i ^ 15>>>4 & ~ia[i-- + (int)d] - (int)d;
b |= (i &= 7) == 5 | (null == null);
d *= (i -= 3) / 13.4;
ia[0]++;
ia[~i | (i+=(!b?2:i))] -= i + 3.3;
// Object += String
o += o + "string";
return 0;
}
void fvoid() {}
}
class Test
{
public void test(TestB a)
{
if(a == this)
{
System.out.println("a is equals to this");
}
}
public static interface TestB
{
public void bla();
}
}
@@ -0,0 +1,14 @@
interface ConflictWithObject {
<error descr="'notify()' cannot override 'notify()' in 'java.lang.Object'; overridden method is final">public void notify()</error>;
}
//--override final-------------------------------------------------------------------------
class base {
final void f() {}
}
class derived extends base {
<error descr="'f()' cannot override 'f()' in 'base'; overridden method is final">void f()</error> {}
}
@@ -0,0 +1,88 @@
// throws conflicts on overriding/ override final
import java.io.*;
import java.net.*;
public class a extends c3 {
public void f() throws <error descr="'f()' in 'a' clashes with 'f()' in 'c3'; overridden method does not throw 'java.lang.Exception'">Exception</error> {
}
}
interface i {
void f() throws java.net.SocketException;
}
class c2 implements i {
public void f() throws <error descr="'f()' in 'c2' clashes with 'f()' in 'i'; overridden method does not throw 'java.io.IOException'">java.io.IOException</error> {}
}
class c2i implements i {
public void f() throws <error descr="'f()' in 'c2i' clashes with 'f()' in 'i'; overridden method does not throw 'java.lang.Exception'">Exception</error> {}
}
class c3 implements i {
public void f() throws java.net.ConnectException {}
}
class c4 extends c3 {
public void f() throws java.net.ConnectException {}
}
interface MethodsFromObject {
Object clone();
}
interface im extends MethodsFromObject {
}
<error descr="'clone()' in 'java.lang.Object' clashes with 'clone()' in 'MethodsFromObject'; overridden method does not throw 'java.lang.CloneNotSupportedException'">class cm implements MethodsFromObject</error> {
}
// sibling inheritance
class c5 { public void f() throws Exception {} }
interface i5 { void f(); }
<error descr="'f()' in 'c5' clashes with 'f()' in 'i5'; overridden method does not throw 'java.lang.Exception'">class c6 extends c5 implements i5</error> {
}
// overriding method does not throw exception, its OK
class c {
protected Object clone() {
return null;
}
}
interface i6 {
}
class b extends c implements i6 {
}
//-------------- methods with same signature
interface AContract
{
void invoke () throws Exception;
}
class A implements AContract
{
public void invoke () throws Exception { }
}
interface BContract
{
void invoke ();
}
class B extends A implements BContract
{
public void invoke () { }
}
class C extends B
{
}
//////////////////////
class Bug extends AbstrColl implements java.io.Serializable {
}
interface Coll {
boolean equals(Object f);
}
class AbstrColl implements Coll {}
@@ -0,0 +1,19 @@
// Qualified new of static class
class A {
b b;
A() {
<error descr="Qualified new of static class">b.new c()</error>;
b.new inner();
}
class inner {}
void f() {
char[] c = <error descr="Invalid qualified new">b.new char[0]</error>;
}
}
class b extends A {
static class c {}
}
@@ -0,0 +1,48 @@
class Outer {
class Inner1 extends Outer {
Inner1() {}
Inner1(Outer o) {}
}
class Inner2 extends Inner1 {
public Inner2(Object o) {
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'Outer'">o</error>.super();
}
public Inner2(int o) {
Outer.this.super();
}
public Inner2(Outer o) {
o.super(Outer.this);
}
public Inner2(Outer o, int par) {
o.super(<error descr="Cannot reference 'this' before supertype constructor has been called">this</error>);
}
public Inner2(Outer o, Object par) {
<error descr="Cannot reference 'this' before supertype constructor has been called">this</error>.super(o);
}
}
class BadInner extends Inner1 {
<error descr="Cannot reference 'BadInner.this' before supertype constructor has been called">BadInner()</error> {}
}
<error descr="Cannot reference 'BadInner2.this' before supertype constructor has been called">class BadInner2 extends Inner1</error> {
}
class s {
void f(Object o) {
new s();
Outer.this.new s();
}
}
}
class Outer2 {
class Inner {}
}
class Ext extends Outer2 {
class ExtInner extends Inner {
ExtInner() {
super();
}
}
}
@@ -0,0 +1,14 @@
class E {
class Outer {
class S {
public static final int SS = 0;
}
}
Outer f() {
int s = <error descr="Expected class or package">f()</error>.S.SS;
int s1 = <error descr="Expected class or package">this</error>.Outer.S.SS;
int s2 = Outer.S.SS;
return null;
}
}
@@ -0,0 +1,154 @@
// reference before ctr called
import java.io.*;
import java.net.*;
class a {
a(int i) {}
a(a a) {}
int f() { return 0; }
int fi;
}
class b extends a {
int bi;
b(int h) {
super(<error descr="Cannot reference 'b.bi' before supertype constructor has been called">bi</error>);
}
b() {
this(<error descr="Cannot reference 'b.bi' before supertype constructor has been called">bi</error>);
}
b(String s) {
super(<error descr="Cannot reference 'b.db' before supertype constructor has been called">db</error>(1) );
}
b(int i, int j) {
super(<error descr="Cannot reference 'a.f' before supertype constructor has been called">f</error>());
}
b(int i, int j, int k) {
super(<error descr="Cannot reference 'a.f' before supertype constructor has been called">super.f</error>());
}
b(String s, int i) {
super(s.length());
}
b(int s, int i, char j) {
super(<error descr="Cannot reference 'a.fi' before supertype constructor has been called">super.fi</error> );
}
b(double d) {
super(new <error descr="Cannot reference 'inner' before supertype constructor has been called">inner</error>() );
}
class inner extends a {inner(){super(1);}}
int db(int j) {
return 0;
}
}
class enc {
int ienc;
class bb extends a {
int ibb;
bb() { super(ienc); }
bb(int i) {
super(i);
}
bb(int i, int j) {
super(<error descr="Cannot reference 'bb.this' before supertype constructor has been called">enc.bb.this</error>.ibb );
}
bb(int i, String s) {
super(enc.this.ienc);
}
bb(int i, char j) {
super(<error descr="Cannot reference 'this' before supertype constructor has been called">this</error> );
}
}
enc() {
this(new <error descr="Cannot reference 'bb' before supertype constructor has been called">bb</error>());
}
enc(bb b) {}
}
// static are OK
class c2 extends a {
static final int fi = 4;
c2() {
super(fi);
}
c2(int i) {
super(sf());
}
static int sf() { return 0; }
c2(int i, int j) {
super(new sc().i);
}
static class sc {
int i;
}
}
interface Callback {
void call();
}
class Base {
Callback callback;
public Base(final Callback callback) {
this.callback = callback;
}
}
class YellinBug extends Base {
public YellinBug() {
super(new Callback() {
public void call() {
<error descr="Cannot reference 'YellinBug.this' before supertype constructor has been called">YellinBug.this</error>.f();
}
});
}
private void f() {}
{
new Callback() {
public void call() {
YellinBug.this.f();
}
};
}
}
class Outer {
class Inner extends Outer{}
class UseIt extends Inner{
Outer o;
UseIt() {
<error descr="Cannot reference 'UseIt.o' before supertype constructor has been called">o</error>.super();
}
Outer geto() {
return null;
}
UseIt(int x) {
<error descr="Cannot reference 'UseIt.geto' before supertype constructor has been called">geto</error>().super();
}
UseIt(Outer x) {
<error descr="Cannot reference 'this' before supertype constructor has been called">this</error>.super();
}
}
}
@@ -0,0 +1,20 @@
class s {
void f() {
<error descr="Cannot return a value from a method with void result type">return 0;</error>
}
void f2() {
return;
}
int f3() {
<error descr="Missing return value">return;</error>
}
int f4() {
return 0;
}
{
<error descr="Return outside method">return;</error>
}
}
@@ -0,0 +1,77 @@
// Serializable/externalizable specific
import java.io.*;
class a implements Serializable {
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
if (stream == null) throw new IOException();
if (stream == null) throw new ClassNotFoundException();
}
private void readObjectNoData() throws ObjectStreamException {
if (this == null) throw new ObjectStreamException(){};
}
private Object readResolve()
throws ObjectStreamException {
if (this == null) throw new ObjectStreamException(){};
return null;
}
private Object writeReplace() { return null; }
private void writeObject(ObjectOutputStream stream) { if (stream==null) return; }
}
class b {
private void <warning descr="Private method 'readObject(java.io.ObjectInputStream)' is never used">readObject</warning>(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
if (stream == null) throw new IOException();
if (stream == null) throw new ClassNotFoundException();
}
private void <warning descr="Private method 'readObjectNoData()' is never used">readObjectNoData</warning>() throws ObjectStreamException {
if (this == null) throw new ObjectStreamException(){};
}
private Object <warning descr="Private method 'readResolve()' is never used">readResolve</warning>()
throws ObjectStreamException {
if (this == null) throw new ObjectStreamException(){};
return null;
}
private Object <warning descr="Private method 'writeReplace()' is never used">writeReplace</warning>() { return null; }
private void <warning descr="Private method 'writeObject(java.io.ObjectOutputStream)' is never used">writeObject</warning>(ObjectOutputStream stream) { if (stream==null) return; }
}
////////////////////////////
abstract class e implements Externalizable {
}
class eImpl extends e {
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
}
class <warning descr="Externalizable class should have public no-args constructor">eImpl1</warning> extends e {
private eImpl1() {}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
}
class <warning descr="Externalizable class should have public no-args constructor">eImpl2</warning> extends e {
public eImpl2(int i) {
System.out.print(i);
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
}
@@ -0,0 +1,37 @@
// silly asignment
import javax.swing.*;
class a {
int f;
JPanel fpanel;
void f(int i) {
<warning descr="Variable is assigned to itself">i = i</warning>;
}
void f2() {
<warning descr="Variable is assigned to itself">this.f = f</warning>;
<warning descr="Variable is assigned to itself">a.this.f = f</warning>;
<warning descr="Variable is assigned to itself">f = this.f</warning>;
}
void f3(Object o) {
int i = 0;
<warning descr="Variable is assigned to itself">i = i</warning>;
<warning descr="Variable is assigned to itself">i = (int)i</warning>;
<warning descr="Variable is assigned to itself">o = ((Object)(o))</warning>;
}
void f4() {
fpanel.getSize().height = this.fpanel.getSize().height; // not silly. Are you sure you can bet getSize() has no side effects?
}
void cf1() {
JPanel a = new JPanel(), b = new JPanel();
a.getSize().height = b.getSize().height; // not silly!
}
void cf2(a aa) {
aa.f = f;
}
}
@@ -0,0 +1,132 @@
// method override
import java.io.*;
import java.net.*;
public class a extends a1 {
<error descr="Static method 'f()' in 'a' cannot override instance method 'f()' in 'a1'">public static void f()</error> { }
<error descr="Instance method 'f1()' in 'a' cannot override static method 'f1()' in 'a1'">public void f1()</error> { }
}
class a1 {
public void f() {}
public static void f1() {}
}
interface i {
void f1();
}
<error descr="Static method 'f1()' in 'a1' cannot override instance method 'f1()' in 'i'">class c_a1_i extends a1 implements i</error> {
}
interface ii {
int f();
}
<error descr="'f()' in 'a1' clashes with 'f()' in 'ii'; attempting to use incompatible return type">abstract class c_a1_ii extends a1 implements ii</error> {
}
interface i2 {
int f1();
}
<error descr="'f1()' in 'i2' clashes with 'f1()' in 'i'; methods have unrelated return types">interface i3 extends i, i2</error> {
}
class weak {
void f1() {}
}
<error descr="'f1()' in 'weak' clashes with 'f1()' in 'i'; attempting to assign weaker access privileges ('packageLocal'); was 'public'">class a2 extends weak implements i</error> {
}
class a3 {
protected void f1() {}
}
<error descr="'f1()' in 'a3' clashes with 'f1()' in 'i'; attempting to assign weaker access privileges ('protected'); was 'public'">class a4 extends a3 implements i</error> {
// public void f1() {}
}
class a5 extends a3 implements i {
// if we override suspicious method, its OK
public void f1() {}
}
// deep inherit
class da1 { void f() {} }
class da2 extends da1 { void f() {} }
class da3 extends da2 {}
interface MyInterface
{
public void myMethod();
}
class MyInterfaceImpl implements MyInterface
{
<error descr="Static method 'myMethod()' in 'MyInterfaceImpl' cannot override instance method 'myMethod()' in 'MyInterface'">public static void myMethod()</error> { /* implementation goes here */ }
<error descr="Static method 'toString()' in 'MyInterfaceImpl' cannot override instance method 'toString()' in 'java.lang.Object'">private static String toString()</error> {
return null;
}
}
// Sun-style inheritance
public class Sunc {
protected void f() {}
}
public class Suncc extends Sunc {
public void f() {}
}
public interface Suni {
public void f();
}
class Sunccc extends Suncc implements Suni {
}
// override static
class StA {
public static StA createInstance() {
return new StA();
}
}
class StB extends StA {
public static <error descr="'createInstance()' in 'StB' clashes with 'createInstance()' in 'StA'; attempting to use incompatible return type">String</error> createInstance() {
return null;
}
}
////////
class Foo {
protected static void foo(String s) {}
}
public class Bar extends Foo{
<error descr="'foo(String)' in 'Bar' clashes with 'foo(String)' in 'Foo'; attempting to assign weaker access privileges ('private'); was 'protected'">private</error> static void foo(String s) {}
}
///////////// IDEADEV-41779
class A {
public static C C() { return new C(); }
}
class B extends A {
}
class C extends B {
public C() {}
}
///////////////////////////
class Z1 {
public static final void doItBaby() {
System.out.println("Hello, diar A");
}
}
class Z2 extends Z1 {
<error descr="'doItBaby()' cannot override 'doItBaby()' in 'Z1'; overridden method is final">public static void doItBaby()</error> {
System.out.println("Hello, diar B");
}
}
///////////////////
@@ -0,0 +1,23 @@
public class Test {
private static final String BAZ = "baz";
private void stringSwitch() {
final String bar = "bar";
String key = "key";
switch (<error>key</error>) {
case "": {
System.out.println("Nothing");
break;
}
case "foo":
case bar:
case BAZ: {
System.out.println("Matched key");
break;
}
default:
break;
}
}
}
@@ -0,0 +1,8 @@
public class Suppressed {
private static final String UNUSED_DECLARATION = "UnusedDeclaration";
@java.lang.SuppressWarnings(UNUSED_DECLARATION)
public static void main(String[] args) {
int i = 0;
}
}
@@ -0,0 +1,84 @@
// unhandled exception when messing with finally block
import java.io.*;
class a {
void f1(int i) {
try {
new FileReader("");
}
finally {
<error descr="Unhandled exception: java.lang.ClassNotFoundException">throw new ClassNotFoundException();</error>
}
}
void f2(int i) {
try {
<error descr="Unhandled exception: java.io.FileNotFoundException">new FileReader("")</error>;
}
finally {
if (i==4) <error descr="Unhandled exception: java.lang.ClassNotFoundException">throw new ClassNotFoundException();</error>
}
}
void f3(int i) {
try {
<error descr="Unhandled exception: java.io.FileNotFoundException">new FileReader("")</error>;
}
finally {
if (i==1) return;
}
}
void f4(int i) {
try {
<error descr="Unhandled exception: java.io.FileNotFoundException">new FileReader("")</error>;
}
finally {
if (i==1) <error descr="Unhandled exception: java.io.FileNotFoundException">throw new FileNotFoundException();</error>
}
}
void cf1(int i) {
try {
new FileReader("");
}
catch (FileNotFoundException e) {
}
finally {
if (1==1) return;
}
}
void cf2(int i) {
try {
new FileReader("");
}
finally {
while (1==1) return;
}
}
void foo(OutputStream out, byte[] data) throws IOException {
out.write(data);
}
public void swallow() {
try {
throw new Exception("Hello World! I'm Checked Exception and must be declared!");
} catch (Exception e) {
throw e;
} finally {
return;
}
}
public void spitout() {
try {
throw new Exception("Hello World! I'm Checked Exception and must be declared!");
} catch (Exception e) {
<error descr="Unhandled exception: java.lang.Exception">throw e;</error>
} finally {
//return;
}
}
}
@@ -0,0 +1,359 @@
// unreachables
import java.io.*;
import java.net.*;
public class a {
interface ii {}
{ // initializer
try {
throw new Exception();
<error descr="Unreachable statement">int i = 5;</error>
}
catch (Exception e) {
}
}
int f1() throws Exception {
return 2;
<error descr="Unreachable statement">return 5;</error>
}
int f2(int i) throws Exception {
if (i==2) return 2;
throw new Exception();
<error descr="Unreachable statement">return 5;</error>
}
int f3(int i) throws Exception {
for (;;) return 2;
<error descr="Unreachable statement">return 5;</error>
}
int f4(int i) throws Exception {
try {
if (i==3) throw new Exception();
return 4;
} finally {
if (i==6) return 9;
}
<error descr="Unreachable statement">return 5;</error>
}
void f5()
{
try {
} catch (Error e) {
throw e;
<error descr="Unreachable statement">;</error>
}
}
void f6() {
try {
}
finally {
return;
<error descr="Unreachable statement">;</error>
}
}
void f7(RuntimeException e) {
for (;;) {
if (e==null) {
return;
<error descr="Unreachable statement">break;</error>
}
}
}
void f8(RuntimeException e,int i,int j,int k,int l) {
for (;;) {
if (e==null) {
return;
<error descr="Unreachable statement">f8(e,i,j,k,l);</error>
}
}
}
void f9(RuntimeException e,int i,int j,int k,int l) {
for (;;) {
if (e==null) {
return;
<error descr="Unreachable statement">throw e;</error>
}
}
}
class Af10 {
int f() {
return 0;
<error descr="Unreachable statement">new Af10();</error>
}
}
class Af11 {
int f() {
return 0;
<error descr="Unreachable statement">int k;</error>
}
void test() {
int i;
return;
<error descr="Unreachable statement">assert i == i;</error>
}
}
int cf1(int i) throws Exception {
if (i==2) return 2;
for (int k=0;1==1;k++) break;
try {
i = 5;
}
catch (Error e) {
if (i==5) return 2;
}
catch (RuntimeException e) {
}
catch (Throwable e) {
}
return 5;
}
int cf2(int i) throws Exception {
switch (i) {
case 1: return 4;
}
return 5;
}
void cf3() {
if (false) {
int i = 5;
}
while (true) { break; }
if (true) {
int i = 4;
}
else {
int i = 6;
}
}
void cf4() throws java.net.SocketException {
try {
bind();
} catch (java.net.SocketException se) {
throw se;
} catch(java.io.IOException e) {
throw new java.net.SocketException(e.getMessage());
}
}
void bind() throws java.net.SocketException {}
void cf5() {
try {
} catch(Exception e) {
}
}
void cf6() {
if (true || true) {
} else {
System.out.println("hi");
}
}
static boolean g() {
return true;
}
public static void main(String[] args) {
boolean b=false && g();
System.out.println("b = "+b);
}
void cf7() {
try {
} finally {
try {
} finally {
}
try {
} finally {
try {
} finally {
}
try {
} finally {
try {
} finally {
try {
} finally {
try {
} finally {
try {
} finally {
}
}
}
}
try {
try {
} finally {
}
} finally {
}
}
}
}
;
}
void cf8() {
class Test01
{
public int testMethod()
{
try
{
throw new Exception("test");
}
catch(Exception e)
{
try
{
throw new Exception("test");
}
catch(Exception ee)
{}
finally
{}
}
finally
{
try
{
throw new Exception("test");
}
catch(Exception e)
{}
finally
{}
}
return 0;
}
}
}
void cf9() {
// should not try to compute constant expression within assert
// since assertions can be disabled/enabled at any moment via JVM flags
assert true;
assert false;
final int i;
if (0==1) {
i = 9;
}
else {
i = 0;
}
}
void cf10() {
int k = 0;
switch (k) {
}
}
private Exception getException()
{
return new java.io.IOException();
}
public void cf11()
{
try {
throw getException();
}
catch (java.io.IOException e) {
e.printStackTrace(); // IDEA claims this to be "Unreachable statement"//
}
catch (Exception e) {
e.printStackTrace();
}
}
//////////////////////////
public void cf12() {
try {
try {
} finally {
doit();
}
} catch (Excep1 e) {
String error = "RollbackException";
} catch (Excep2 e) {
String error = "HeuristicRollbackException";
} catch (Excep3 e) {
String error = "SystemException";
} catch (IllegalStateException e) {
String error = "IllegalStateException";
} catch (RuntimeException e) {
String error = "RuntimeException";
}
}
private void doit() throws Excep1, Excep2, Excep3{
//To change body of created methods use Options | File Templates.
}
class Excep1 extends Exception {}
class Excep2 extends Exception {}
class Excep3 extends Exception {}
public void cf13() throws Exception {
while (true) {
try {
cf13();
} finally {
continue;
}
}
}
}
class NestedFinallyTest {
void ftest4() {
try {
}
finally {
try {
}
finally {
try {
}
finally {
try {
}
catch (Throwable t4) {
}
}
}
}
ftest4();
}
}
@@ -0,0 +1,46 @@
public class a extends Exception {
private <warning descr="Private constructor 'a(java.lang.String)' is never used">a</warning>(String s) {
super(s);
}
}
class s extends Exception {
private s(String s) {
super(s);
}
public s create() {
return new s("");
}
}
class PrivateClassTest {
private static class Test1 {
// Complains that this constructor is never used
private Test1 () {}
private Test1 (String s) {
System.out.println(s);
}
}
private static class Test2 extends Test1 {
// Complains that no default constructor is available
public Test2 () {
}
// Complains that the relevant constructor has private access
public Test2 (String s) {
super (s);
}
}
public static void main(String[] args) {
System.out.println(new Test2());
}
private void <warning descr="Private method 'f(boolean, int)' is never used">f</warning>(boolean b,
int <warning descr="Parameter 'param' is never used">param</warning>) {
if (b) {
f(b, param);
}
}
}
@@ -0,0 +1,19 @@
public class <warning descr="Class 'XXX' is never used">XXX</warning> {
void <warning descr="Method 'fffff()' is never used">fffff</warning>(){}
public void <warning descr="Method 'asdfaffffff()' is never used">asdfaffffff</warning>(){}
protected void <warning descr="Method 'dasklfjhsad()' is never used">dasklfjhsad</warning>(){}
String <warning descr="Field 'asdfadsf' is never used">asdfadsf</warning>;
public String <warning descr="Field 'asdasdfadsf' is never used">asdasdfadsf</warning>;
static class <warning descr="Class 'sasdfasdfasd' is never used">sasdfasdfasd</warning> {}
public <warning descr="Constructor 'XXX()' is never used">XXX</warning>() {}
// overloaded
void fffff(String i){i.hashCode();}
{
fffff(null);
}
}
@@ -0,0 +1,9 @@
public class WithMain {
public static void main(String[] args){
}
public void myTestMethod(){}
}
@@ -0,0 +1,19 @@
class Sup {
protected void f(int i){}
}
class Foo extends Sup {
public void foo(int <warning descr="Parameter 'i' is never used">i</warning>){}
public void g(int i){}
protected void f(int i){}
}
class Sub extends Foo {
public void g(int i){}
}
interface fff {
void f(int ggggg);//
}
abstract class ab {
public abstract void f(int ggggg);//
}
@@ -0,0 +1,19 @@
class Sup {
protected void f(int i){}
}
class Foo extends Sup {
public void foo(int i){}
public void g(int i){}
protected void f(int i){}
}
class Sub extends Foo {
public void g(int i){}
}
interface fff {
void f(int ggggg);//
}
abstract class ab {
public abstract void f(int ggggg);//
}
@@ -0,0 +1,34 @@
class s {
void f() {
int i;
int <error descr="Variable 'i' is already defined in the scope">i</error>;
}
void f1() {
int i;
{
int <error descr="Variable 'i' is already defined in the scope">i</error>;
}
}
void f2() {
int i;
class ss
{
int i;
}
}
int <error descr="Variable 'f' is already defined in the scope">f</error>;
int <error descr="Variable 'f' is already defined in the scope">f</error>;
void f3() {
int f;
}
public void tutu(String e) {
try {
Integer.parseInt("3");
} catch (NumberFormatException <error descr="Variable 'e' is already defined in the scope">e</error>) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,25 @@
class s {
void f() {
int i;
int <error descr="Variable 'i' is already defined in the scope">i</error>;
}
void f1() {
int i;
{
int <error descr="Variable 'i' is already defined in the scope">i</error>;
}
}
void f2() {
int i;
class ss
{
int i;
}
}
int f;
int <error descr="Variable 'f' is already defined in the scope">f</error>;
void f3() {
int f;
}
}
@@ -0,0 +1,5 @@
import java.io.*;
public class x {
static {int i;}
}
@@ -0,0 +1,31 @@
// string literal
public class a {
char c1 = <error descr="Empty character literal">''</error>;
char c2 = <error descr="Illegal escape character in character literal">'\dd'</error>;
char c4 = <error descr="Too many characters in character literal">'xxx'</error>;
char c5 = <error descr="Too many characters in character literal">'\78'</error>;
char c6 = <error descr="Too many characters in character literal">'\78'</error>;
char[] cA = new char[] { 'd','\b','\f','\n','\r'
,'\t','"','\\',' ','\u1234','\uFFFF'
, '\7', '\77', '\345', '\0'};
String s1 = <error descr="Illegal escape character in string literal">"\xd"</error>;
String s11= <error descr="Illegal escape character in string literal">"\udX"</error>;
String s12= <error descr="Illegal escape character in string literal">"c:\TEMP\test.jar"</error>;
String s3 = "";
String s4 = "\u0000";
String s5 = <error descr="Illegal escape character in string literal">"\u000d"</error>;
String s6 = <error descr="Illegal escape character in string literal">"\u000a"</error>;
char c7 = <error descr="Illegal escape character in character literal">'\u000d'</error>;
char c8 = <error descr="Illegal escape character in character literal">'\u000a'</error>;
void foo(String a) {
foo(<error descr="Illegal line end in string literal">"aaa</error>
);
}
}
@@ -0,0 +1,106 @@
//statics in inner
public class a {
static final Number x = null;
static final int ix = x== null ? 4 : 3;
class ic {
<error descr="Inner classes cannot have static declarations">static</error>
int i;
<error descr="Inner classes cannot have static declarations">static</error>
final int f1 = 3 < 4 ? (a.ix==5 ? 1 : 3) / 4 + 18 : 0;
<error descr="Inner classes cannot have static declarations">static</error>
final int f2 = x instanceof Integer ? 1 : 0;
<error descr="Inner classes cannot have static declarations">static</error>
class a_ic_c {}
<error descr="Inner classes cannot have static declarations">interface a_ic_i</error> {}
<error descr="Inner classes cannot have static declarations">static</error> interface a_ic_i2 {}
<error descr="Inner classes cannot have static declarations">static</error>
int a_ic_m(String s) { return 0; }
// static initializer
<error descr="Inner classes cannot have static declarations">static</error>
{}
}
interface ii {
static int i = 9;
void f();
// since nested interface is implicitly static:
static class ii_c {}
}
// static inside class inside code block
void f() {
class ic2 {
<error descr="Inner classes cannot have static declarations">static</error>
int i;
<error descr="Inner classes cannot have static declarations">static</error>
final int f1 = 3 < 4 ? (a.ix==5 ? 1 : 3) / 4 + 18 : 0;
<error descr="Inner classes cannot have static declarations">static</error>
final int f2 = x instanceof Integer ? 1 : 0;
<error descr="Inner classes cannot have static declarations">static</error>
class a_ic_c2 {}
<error descr="Inner classes cannot have static declarations">static</error>
int a_ic_m2(String s) { return 0; }
// static initializer
<error descr="Inner classes cannot have static declarations">static</error>
{}
}
}
void f1()
{
new a() {
<error descr="Inner classes cannot have static declarations">static</error>
int i;
<error descr="Inner classes cannot have static declarations">static</error>
final int f1 = 3 < 4 ? (a.ix==5 ? 1 : 3) / 4 + 18 : 0;
// its not a compile time constant
<error descr="Inner classes cannot have static declarations">static</error>
final Object o = null;
<error descr="Inner classes cannot have static declarations">static</error>
final int f2 = x instanceof Integer ? 1 : 0;
<error descr="Inner classes cannot have static declarations">static</error>
class a_ic_c2 {}
<error descr="Inner classes cannot have static declarations">static</error>
int a_ic_m2(String s) { return 0; }
// static initializer
<error descr="Inner classes cannot have static declarations">static</error>
{}
};
}
// local interface
class cc {
void f() {
<error descr="Modifier 'interface' not allowed here">interface i</error> {}
}
void ff() {
class inn {
<error descr="Inner classes cannot have static declarations">interface i</error> {}
}
}
Object o = new Runnable() {
<error descr="Inner classes cannot have static declarations">interface i</error> {}
public void run() {}
};
}
}
@@ -0,0 +1,102 @@
// casts
public class a {
void f(i ii) {
boolean b;
b = <error descr="Inconvertible types; cannot cast 'int' to 'a'">2 instanceof a</error>;
b = <error descr="Inconvertible types; cannot cast 'null' to 'int'">null instanceof int</error>;
b = <error descr="Inconvertible types; cannot cast 'c3' to 'java.lang.Boolean'">(c3)null instanceof Boolean</error>;
b = ii instanceof i;
b = ((c2)ii) instanceof c4;
b = null instanceof a;
b = ii instanceof c3;
b = Boolean.valueOf("true") instanceof Boolean;
b = new Long(3) instanceof Number;
b = this instanceof a;
b = ii instanceof a;
b = this instanceof i;
// casts
c2 c2i = null;
c3 c3i = null;
c4 c4i = null;
Object o;
c4i = <error descr="Inconvertible types; cannot cast 'a' to 'c4'">(c4) this</error>;
o = <error descr="Inconvertible types; cannot cast 'c2' to 'boolean'">(boolean) c2i</error>;
o = <error descr="Inconvertible types; cannot cast 'c3' to 'java.lang.Integer'">(Integer) c3i</error>;
o = <error descr="Inconvertible types; cannot cast 'c2' to 'a'">(a) c2i</error>;
o = <error descr="Inconvertible types; cannot cast 'c3' to 'int'">(int) c3i</error>;
o = (a) ii;
o = (i) c4i; //cast to interface
o = (c3) c2i;
o = (c3) c3i;
o = (c3) c4i;
o = (Object) ii;
o = (iunrelated) ii;
o = (iunrelated) c2i;
o = (c4) c2i;
o = (c4) ii;
o = <error descr="Inconvertible types; cannot cast 'i' to 'c5'">(c5) ii</error>;
int[] ai = null;
o = <error descr="Inconvertible types; cannot cast 'int[]' to 'byte[]'">(byte[])ai</error>;
o = <error descr="Inconvertible types; cannot cast 'int[]' to 'double[]'">(double[])ai</error>;
c3[] ac3i = null;
o = ac3i;
o = (c4[])ac3i;
o = (i[])ac3i;
Object[] results = null;
int index = (<error descr="Inconvertible types; cannot cast 'java.lang.Object[]' to 'java.lang.Integer'">(Integer) results</error>).intValue();
// arrays and Serializable/Cloneable/Object
int[] ai2 = (int[])o;
Cloneable cloneable = null;
ai2 = (int[]) cloneable;
java.io.Serializable serializable = null;
ai2 = (int[]) serializable;
}
}
interface iunrelated {}
interface i {}
class c2 implements i {
public c2() {}
public void f() {}
protected void g() {}
}
class c3 extends c2 {
protected c3() {}
private int g(int k) { return 0; }
}
final class c4 extends c3 {
private c4() {
int[] a=new int[3];
Cloneable s=a;
java.io.Serializable ss = a;
}
}
final class c5 {}
// clashing interfaces
interface A {
void g();
}
interface B {
int g();
}
interface BB extends B {
}
class Foo {
void f(A a) {
B b = <error descr="Inconvertible types; cannot cast 'A' to 'B'">(B) a</error>;
BB b2 = <error descr="Inconvertible types; cannot cast 'A' to 'BB'">(BB) a</error>;
A a2 = <error descr="Inconvertible types; cannot cast 'BB' to 'A'">(A) b2</error>;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,150 @@
// vars double initialization
import java.io.*;
import java.net.*;
public class a21 {
void f1(int i) {
final int j;
j = 2;
<error descr="Variable 'j' might already have been assigned to">j</error> = 2;
}
void f2(int i) {
final int j;
if (i==3) j = 2;
else j = 5;
<error descr="Variable 'j' might already have been assigned to">j</error> = 2;
}
void f3(int i) {
final int j;
if (i==4) j = 2;
<error descr="Variable 'j' might already have been assigned to">j</error> = 2;
}
void f5(int i) {
final int j;
j = 2;
if (i==3) return;
<error descr="Variable 'j' might already have been assigned to">j</error> = 2;
}
void f6(int i) {
final int j;
switch (i) {
case 1: j = 2;
}
<error descr="Variable 'j' might already have been assigned to">j</error> = 2;
}
void f7(int i) {
final int j;
while (i < 4) {
<error descr="Variable 'j' might be assigned in loop">j</error> = 2;
final int ii = 4;
i+=ii;
}
}
void f8(String k) {
if (k != null) {
final String i;
if (k.equals("!")) i = "3";
if (k.equals("!")) <error descr="Variable 'i' might already have been assigned to">i</error> = "2";
}
}
void f9() {
final Object type;
try {
type = null;
}
catch (Exception e) {
<error descr="Variable 'type' might already have been assigned to">type</error> = null;
}
}
void f10() {
final int k;
if (false) {
k=0;
//< error descr="Variable 'k' might already have been assigned to">k< /error>=0;
}
}
class Foo {
final int k;
Foo() {
k=0;
<error descr="Variable 'k' might already have been assigned to">k</error>=0;
}
}
void cf1(int i) {
final int j;
final int j1 = 3;
j = 5;
final int unused;
final int j2;
if (j == 3) j2 = 4;
final int j3;
if (j==4) j3 = 5;
else j3 = 6;
final int j4 = j3 + 6;
final int j5;
while (i != 9) {
if (j == 8) {
j5 = 9;
break;
}
}
}
final boolean FB = true;
void cf2() {
final int k;
if (!FB) {
k = 4;
}
// < error descr="Variable 'k' might already have been assigned to">k< /error>=0;
}
// todo:
// in IDEA Variable 'b' might not have been initialized
// in javac: OK
/*
void f2() {
boolean b;
boolean c = true;
if (c && false) {
c = b;
}
}
*/
}
class A {
final int k;
A() {
for (;;) {
<error descr="Variable 'k' might be assigned in loop">k</error>=0;
}
}
}
class Example {
public int method(boolean b) {
if (b) {
final int indent;
indent = 0;
return 0;
}
else {
new <error>Runnable</error>(){}<EOLError/>
}
<error>}</error>
}
@@ -0,0 +1,118 @@
// fields double initialization
import java.io.*;
import java.net.*;
class Foo {
final int k;
final int ff = 5;
Foo(int i) {
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
{
k=0;
}
}
class c2 {
static final int k;
static {
k=0;
}
c2() {
int i = k;
}
static {
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
}
class c3 {
final int k;
{
k=0;
}
c3() {
int i = k;
}
{
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
}
class c4 {
final int k;
{
k=0;
}
c4(int i) {
if (false)
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
c4() {
this(0);
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
}
// redirected ctrs
class c5 {
<error descr="Variable 'k' might not have been initialized">final int k</error>;
c5(int i) {
k =1;
}
c5() {
this(0);
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
c5(char c) {
}
c5(int i, int j) {
this('c');
k = 5;
}
c5(String s) {
this(0,0);
<error descr="Variable 'k' might already have been assigned to">k</error> =1;
}
}
class c6 {
final int i;
c6() {
this(0);
}
c6(int i) {
this(0,0);
}
c6(int k, int l) {
i = k;
}
}
// multiple initalizers
class c7 {
private final String x;
{
x = "Hello";
}
private final String y;
{
y = x;
}
private static int i;
{
int j = 0;
}
static {
i = 9;
}
{
<error descr="Variable 'y' might already have been assigned to">y</error> = ""+i;
}
}
@@ -0,0 +1,178 @@
// unhandled exceptions from superclases/etc
import java.io.*;
import java.net.*;
public class a {
a(int i) {}
}
// super ctr
<error descr="There is no default constructor available in 'a'">class b extends a</error> {
}
class c extends a {
<error descr="There is no default constructor available in 'a'">c()</error> {
}
c(String s) {
this(1);
}
c(int i) {
super(i);
}
}
class A {
private A() {}
class B extends A {}
}
class A1 {
A1() throws Exception {}
}
<error descr="Unhandled exception: java.lang.Exception">class B1 extends A1</error>
{}
class A2 extends A1 {
<error descr="Unhandled exception: java.lang.Exception">A2()</error> {}
}
// exception thrown from within anonymous
class A3 {
void f() throws Exception {
new A3() {
int g() throws Exception {
return 0;
}
int k=g();
};
}
}
// in initializer
class Test{
final String s = <error descr="Unhandled exception: java.lang.Exception">makeString();</error>
String makeString() throws Exception {throw new Exception();}
}
class C1 {
public C1() throws IllegalArgumentException {}
}
class C2 extends C1 {
public C2() {
}
}
// private but accessible base ctr
class D1 {
private D1() {}
static class D2 extends D1 {
D2() {
System.out.println("!");
}
}
public static void main(String[] args) {
new D2();
new D1();
}
}
///////////////
class MyClass
{
public MyClass() throws Exception
{
//default ctor throws exc
}
public MyClass(Object anObject)
{
//other ctor does not
}
}
class MyClass2 extends MyClass
{
//HERE good code is marked red
public MyClass2 (Object anObject)
{
super(anObject);
}
}
class ThrowCC {
public void test3() throws Exception {
Throwable exception = null;
<error descr="Unhandled exception: java.lang.Throwable">throw exception;</error>
}
}
//Inaccessible field
class J {
int t = new I1().i; //access object class is OK
int v = new I2().<error descr="'i' has private access in 'J.I1'">i</error>; //bad access object class
class I1 {
class I3 {
int t = i; //visibility OK
}
private int i;
}
class I2 extends I1 {
int j = <error descr="'i' has private access in 'J.I1'">i</error>; //We don't see i from baser class
}
static I1 i1;
class I4 {
int u = i1.i; //OK, i is visible since the toplevel class is the same
}
}
class Test3 {
private class Child extends Parent {
}
private class Parent extends SuperParent {
}
private class SuperParent {
private int field = 1;
}
public void foo() {
Child child = new Child();
int i = child.<error descr="'field' has private access in 'Test3.SuperParent'">field</error>;
}
}
//IDEADEV-4455: this code is OK
class XYZ {
private class Inner extends XYZ {
private final String s;
Inner(String _s) {
this.s = _s;
}
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Inner y = (Inner) o;
if (s != null ? !s.equals(y.s) : y.s != null) return false;
return true;
}
}
}
//end of IDEADEV-4455
@@ -0,0 +1,46 @@
/// assignment compatible types
import java.io.*;
import java.net.*;
public class a {
final int FI = 2;
final int FIBIG = 200000000;
void f() {
// not marked: OK, as literal value is in byte-range
byte b1 = 1;
// marked: OK, as literal value is out of byte-range and does not compile
<error descr="Incompatible types. Found: 'int', required: 'byte'">byte b2 = 1000;</error>
// marked: OK, as char-value cannot be determined and does not compile
char c = 0;
<error descr="Incompatible types. Found: 'char', required: 'byte'">byte b3 = c;</error>
// marked: OK, as literal char-value is out of byte-range and does not compile
<error descr="Incompatible types. Found: 'char', required: 'byte'">byte b4 = '\u20AC';</error>
<error descr="Incompatible types. Found: 'int', required: 'byte'">byte b5 = '\n' - 4 + 1800;</error>
// literal char-value is in byte-range and compiles fine
byte b6 = '\u007F';
byte b7=(short) 0;
<error descr="Incompatible types. Found: 'long', required: 'byte'">byte b8 = (long)0;</error>
<error descr="Incompatible types. Found: 'double', required: 'float'">float f1 = 77.3;</error>
float f2 = 77.3F;
short s1 = 1 + FI;
<error descr="Incompatible types. Found: 'int', required: 'short'">short s2 = 1000000;</error>
short s3 = 'F' % FIBIG;
char c1 = 0;
<error descr="Incompatible types. Found: 'int', required: 'char'">char c2 = -1 + FIBIG;</error>
char c3=(byte) 0;
char c4=(short) 0;
<error descr="Incompatible types. Found: 'long', required: 'char'">char c5 = 0L;</error>
int i1='d';
<error descr="Incompatible types. Found: 'long', required: 'int'">int i2 = 1L;</error>
}
}
@@ -0,0 +1,42 @@
/// labels
import java.io.*;
import java.net.*;
public class a {
void f(final boolean b) {
while (b) break <error descr="Undefined label: 'lab1'">lab1</error>;
while (b) continue <error descr="Undefined label: 'lab1'">lab1</error>;
for (;;) {
lab2: ;
break <error descr="Undefined label: 'lab2'">lab2</error>;
continue <error descr="Undefined label: 'lab2'">lab2</error>;
}
lab3:
new Runnable() {
public void run() {
while (true) {
if (b) break <error descr="Undefined label: 'lab3'">lab3</error>;
if (b) continue <error descr="Undefined label: 'lab3'">lab3</error>;
}
}
};
}
void cf() {
boolean b = false;
while (b) {
lab0: break lab0;
}
lab1: try {
lab2: for (;b;) if (1==3) continue lab2;
break lab1;
}
finally {
break lab1;
}
}
}
@@ -0,0 +1,74 @@
/// forward references
import java.io.*;
import java.net.*;
public class a {
{
int i;
if (<error descr="Illegal forward reference">FI</error> == 4) i = 5;
}
final int FI = 4;
int k = 1 + <error descr="Illegal forward reference">ki</error>;
int ki;
final int fi5 = <error descr="Illegal forward reference">fi5</error> + 1;
}
class a1 {
static int i = <error descr="Illegal forward reference">j</error> + 2;
static int j = 4;
}
class a2 {
static { i = <error descr="Illegal forward reference">j</error> + 2; }
static int i, j;
static { j = 4; }
}
// pasted from JLS 8.3.2.3
class UseBeforeDeclaration {
static {
x = 100; // ok - assignment
int y = <error descr="Illegal forward reference">x</error> + 1; // error - read before declaration
int v = x = 3; // ok - x at left hand side of assignment
int z = UseBeforeDeclaration.x * 2; // ok - not accessed via simple name
Object o = new Object(){
void foo(){x++;} // ok - occurs in a different class
{x++;} // ok - occurs in a different class
};
}
{
j = 200; // ok - assignment
j = <error descr="Illegal forward reference">j</error> + 1; // error - right hand side reads before declaration
int k = j = <error descr="Illegal forward reference">j</error> + 1;
int n = j = 300; // ok - j at left hand side of assignment
int h = <error descr="Illegal forward reference">j</error>++; // error - read before declaration
int l = this.j * 3; // ok - not accessed via simple name
Object o = new Object(){
void foo(){j++;} // ok - occurs in a different class
{ j = j + 1;} // ok - occurs in a different class
};
}
int w = x= 3; // ok - x at left hand side of assignment
int p = x; // ok - instance initializers may access static fields
static int u = (new Object(){int bar(){return x;}}).bar(); // ok - occurs in a different class
static int x;
int m = j = 4; // ok - j at left hand side of assignment
int o = (new Object(){int bar(){return j;}}).bar(); // ok - occurs in a different class
int j;
}
class a3 {
static {
<error descr="Illegal forward reference">i</error>+=1;
}
static int j=<error descr="Illegal forward reference">i</error>+=1;
static int i=0;
{
<error descr="Illegal forward reference">k</error>+=1;
}
int n=<error descr="Illegal forward reference">k</error>+=1;
int k=0;
}
@@ -0,0 +1,40 @@
// cyclic inhertiance
import java.io.*;
import java.net.*;
<error descr="Cyclic inheritance involving 'Foo'">class Foo extends Foo</error> {
}
interface Foo1 extends <error descr="Cannot resolve symbol 'Bar'">Bar</error> {
interface Bar {
}
}
<error descr="Cyclic inheritance involving 'c1'">class c1 extends c2</error> {}
<error descr="Cyclic inheritance involving 'c2'">class c2 extends c1</error> {}
class a1 {
class b extends a1 {
}
}
class a {
static class sb extends a {
class c extends a {
void f() {
class d extends a {
}
}
}
}
class b extends sb {
class c extends a {
}
}
}
@@ -0,0 +1,69 @@
// labels
import java.io.*;
import java.net.*;
class a {
void f() {
<error descr="Label without statement">a:</error>
}
void f1() {
a:
<error descr="Label without statement">b:</error>
}
void f2() {
a: return;
}
void f3() {
a: return;
}
void f4() {
a:
b:
return;
}
void f5() {
a:
if (4==5) return;
b: ;
}
void f6() {
a: ;
}
}
class AlreadyInUse {
void f0() {
a: {
f0();
<error descr="Label 'a' already in use">a</error>: f0();
}
}
void f1() {
a:
try {
f1();
<error descr="Label 'a' already in use">a</error>:
f1();
}
finally {
}
}
void f2() {
{
a:;
}
{
a:;
}
}
void f3() {
a:
new Object() {
void f() {
a:;
}
};
}
}
@@ -0,0 +1,8 @@
// unclosed comment
/*
import java.io.*;
import java.net.*;
class a {
<error descr="Unclosed comment">}</error>
@@ -0,0 +1,9 @@
// unclosed comment
import java.io.*;
import java.net.*;
/**
class a {
int i<error descr="Unclosed comment">;</error>
@@ -0,0 +1,3 @@
// unclosed decl
class a {<EOLError/>
@@ -0,0 +1,31 @@
// ternary operator
class a {
void f1() {
byte b = 4;
int i = 2;
boolean bo = false;
long l = 5;
float f = 5;
double d = 45;
String s;
<error descr="Incompatible types. Found: 'int', required: 'java.lang.String'">s = bo ? 1 : 2</error>;
<error descr="Incompatible types. Found: 'long', required: 'java.lang.String'">s = bo ? 1L: 2</error>;
<error descr="Incompatible types. Found: 'byte', required: 'java.lang.String'">s = bo ? b : 2</error>;
<error descr="Incompatible types. Found: 'int', required: 'java.lang.String'">s = bo ? b : b+2</error>;
<error descr="Incompatible types. Found: 'long', required: 'java.lang.String'">s = bo ? b+1L : 2</error>;
<error descr="Incompatible types. Found: 'float', required: 'java.lang.String'">s = bo ? f : f+2</error>;
<error descr="Incompatible types. Found: 'double', required: 'java.lang.String'">s = bo ? d : 2</error>;
}
void cf1() {
byte[] byteArr = new byte[10];
boolean bool = true;
byte i = bool ? byteArr[0] : 0;
}
}
@@ -0,0 +1,12 @@
// duplicates in extends
class a {
}
class b extends <error descr="Duplicate class: 'a'">a</error>, <error descr="Duplicate class: 'a'">a</error> {
}
interface i {}
class c implements <error descr="Duplicate class: 'i'">i</error>, <error descr="Duplicate class: 'i'">i</error> {
}
@@ -0,0 +1,32 @@
// exception java.lang.Exception has already been caught/ illegal catch type
import java.io.EOFException;
import java.io.IOException;
class Foo {
void f() {
try {
} catch (Throwable t) {
} catch (<error descr="Exception 'java.lang.Exception' has already been caught">Exception</error> e) {
}
try {
} catch (RuntimeException e) {
} catch (<error descr="Exception 'java.lang.NullPointerException' has already been caught">NullPointerException</error> e) {
}
try {
throw new EOFException();
} catch (IOException e) {
} catch (<error descr="Exception 'java.io.EOFException' has already been caught">EOFException</error> e) {
}
try {
}
catch (Exception e) {
}
catch (<error descr="Exception 'java.lang.Exception' has already been caught">Exception</error> e) {
}
}
}
@@ -0,0 +1,54 @@
// constant expressions in switch
import java.util.Date;
class a {
final int f = -3;
void f1() {
switch (0) {
case <error descr="Constant expression required">new Integer(0).MAX_VALUE</error>:
}
int k=0;
switch (0) {
case <error descr="Constant expression required">false ? k : 0</error>:
case <error descr="Constant expression required">true ? 1 : k</error>:
}
boolean b=true;
switch (0) {
case <error descr="Constant expression required">false && b ? 0 : 1</error>:
case <error descr="Constant expression required">true || b ? 2 : 0</error>:
}
final Object obj="";
switch (0) {
case <error descr="Constant expression required">obj=="" ? 0 : 0</error>:
case <error descr="Constant expression required">this.f</error>:
}
int i = 0;
final Integer I = null;
switch (0) {
case <error descr="Constant expression required">i</error>:
case <error descr="Constant expression required">I.MAX_VALUE</error>:
case Integer.MAX_VALUE:
}
}
static class b {
static final int c = 8;
}
void cf1() {
final int i = 9;
switch (0) {
case i:
case 2+4:
case f:
case a.b.c:
}
switch (0) {
case true ^ true ? 0 : 0:
}
}
}
@@ -0,0 +1,55 @@
// access problems in inner classes
import java.awt.*;
import java.beans.beancontext.BeanContextServicesSupport;
import java.beans.beancontext.BeanContextServicesSupport.<error descr="'java.beans.beancontext.BeanContextServicesSupport.BCSSChild' has protected access in 'java.beans.beancontext.BeanContextServicesSupport'">BCSSChild</error>;
class a extends Component {
void f() {
FlipBufferStrategy s = null;
int i = s.<error descr="'numBuffers' has protected access in 'java.awt.Component.FlipBufferStrategy'">numBuffers</error>;
s.<error descr="'createBuffers(int, java.awt.BufferCapabilities)' has protected access in 'java.awt.Component.FlipBufferStrategy'">createBuffers</error>(1,null);
// TODO
// now cannot distinquish private from package local in class files
//< error descr="'java.awt.Component.SingleBufferStrategy' has private access in 'java.awt.Component'">SingleBufferStrategy< /error> s2 = null;
//Object o = s2.< error descr="'caps' has private access in 'java.awt.Component.SingleBufferStrategy'">caps< /error>;
}
class ddd extends BeanContextServicesSupport {
BCSSChild.<error descr="'java.beans.beancontext.BeanContextServicesSupport.BCSSChild.BCSSCServiceClassRef' is not public in 'java.beans.beancontext.BeanContextServicesSupport.BCSSChild'. Cannot be accessed from outside package">BCSSCServiceClassRef</error> fd = null;
void ff() {
fd.<error descr="'addRequestor(java.lang.Object, java.beans.beancontext.BeanContextServiceRevokedListener)' is not public in 'java.beans.beancontext.BeanContextServicesSupport.BCSSChild.BCSSCServiceClassRef'. Cannot be accessed from outside package">addRequestor</error>(null,null);
}
}
}
interface I {
abstract class Imple implements I {
abstract void f();
}
abstract class Impl2 extends Imple {
abstract class Inner extends Impl2 {
}
}
}
class Class1 extends Class2 {
public void test() {
new <error descr="'Class2.Class2Inner' has private access in 'Class2'">Class2Inner</error>();
int i = <error descr="'Class2.Class2Inner' has private access in 'Class2'">Class2Inner</error>.i;
}
}
class Class2 {
private static class Class2Inner{
public static int i;
public Class2Inner() {
}
}
}
@@ -0,0 +1,35 @@
// switch statement
class a {
{
<error descr="Case statement outside switch">case 0:</error>
}
{
<error descr="Case statement outside switch">default:</error>
}
{
switch (0) {
case 0<error descr="':' expected">;</error>
}
switch (0) {
default<error descr="':' expected">;</error>
}
switch (0) {
////////////////
/**
*/
<error descr="Statement must be prepended with case label">System.out.println();</error>
default<error descr="':' expected">;</error>
}
switch (0) {
<error descr="Statement must be prepended with case label">break;</error>
}
}
}
@@ -0,0 +1,12 @@
// assert statement
class a {
void f() {
assert false : <error descr="'void' type is not allowed here">System.out.println()</error>;
assert <error descr="Incompatible types. Found: 'int', required: 'boolean'">0</error>;
assert <error descr="Incompatible types. Found: 'char', required: 'boolean'">'a'</error>;
assert <error descr="Incompatible types. Found: 'java.lang.String', required: 'boolean'">""</error>;
assert <error descr="Incompatible types. Found: 'void', required: 'boolean'">f()</error>;
}
}
@@ -0,0 +1,20 @@
// sync statement
class a {
void f() {
synchronized (<error descr="Incompatible types. Found: 'null', required: 'java.lang.Object'">null</error>) {
}
synchronized (<error descr="Incompatible types. Found: 'int', required: 'java.lang.Object'">0</error>) {
}
synchronized (<error descr="Incompatible types. Found: 'char', required: 'java.lang.Object'">'a'</error>) {
}
synchronized (<error descr="Incompatible types. Found: 'boolean', required: 'java.lang.Object'">true</error>) {
}
synchronized (<error descr="Incompatible types. Found: 'void', required: 'java.lang.Object'">System.out.println()</error> ) {
}
}
}
@@ -0,0 +1,16 @@
// multiple extend
import java.io.*;
class c1 {}
class c2 implements Serializable, Externalizable {
public void writeExternal(ObjectOutput out) throws IOException {
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
}
class a <error descr="Class cannot extend multiple classes">extends c1,c2</error> {
}
@@ -0,0 +1,37 @@
// recusrsive ctr call
class s {
<error descr="Recursive constructor invocation">s()</error> {
this();
}
<error descr="Recursive constructor invocation">s(int i)</error> {
this(2);
}
}
class c {
c() {
this(2);
}
<error descr="Recursive constructor invocation">c(int i)</error> {
this(1,1);
}
<error descr="Recursive constructor invocation">c(int i, int k)</error> {
this(1);
}
}
class cv {
cv() {
this(1);
}
cv(int i) {
this(1,2);
}
cv(int i,int j) {}
}
@@ -0,0 +1,11 @@
// single import conflict
import java.sql.Date;
<error descr="'java.sql.Date' is already defined in a single-type import">import java.util.Date;</error>
import java.sql.*;
import java.util.*;
// multiple single-type import of the same class is fine
import java.io.IOException;
import java.io.IOException;
public class c {}

Some files were not shown because too many files have changed in this diff Show More