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,9 @@
@Deprecated @SuppressWarnings("")
<error descr="Class 'Foo' must either be declared abstract or implement abstract method 'run()' in 'Runnable'">public class Foo implements Runnable</error> {
}
class F {
@Deprecated @SuppressWarnings("") <error descr="'f()' is already defined in 'F'">void f()</error> {}
@Deprecated @SuppressWarnings("") <error descr="'f()' is already defined in 'F'">void f()</error> {}
}
@@ -0,0 +1,69 @@
public class Autoboxing {
public boolean compare(short s, Integer i) {
return i == s; //OK, i is unboxed
}
public boolean compare(Short s, Integer i) {
return <error descr="Operator '==' cannot be applied to 'java.lang.Integer','java.lang.Short'">i == s</error>; //comparing as references
}
void f(Integer i) {
switch(i) {
default:
}
}
{
Object data = 1;
boolean is1 = <error descr="Operator '==' cannot be applied to 'java.lang.Object','int'">data == 1</error>;
}
//IDEADEV-5549: Short and double are convertible
public static double f () {
Short s = 0;
return (double)s;
}
//IDEADEV-5613
class DumbTest {
private long eventId;
public int hashCode() {
return ((Long) eventId).hashCode();
}
}
public static void main(String[] args) {
Long l = 0L;
Short s = 0;
int d = <error descr="Inconvertible types; cannot cast 'java.lang.Long' to 'int'">(int)l</error>;
d = (int)s;
short t = 0;
Integer d1 = <error descr="Inconvertible types; cannot cast 'short' to 'java.lang.Integer'">(Integer) t</error>;
Byte b = <error descr="Inconvertible types; cannot cast 'short' to 'java.lang.Byte'">(Byte) t</error>;
}
{
{
boolean cond = true;
// test for JLS3 bug, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6888770
Byte B = 0;
byte b = 0;
byte value = cond ? B : b; /////////
short s = 0;
Short S = 0;
short rs = cond ? S : s;
char c = 0;
Character C = 0;
char rc = cond ? C : c;
boolean bb = cond ? Boolean.FALSE : true;
}
}
}
@@ -0,0 +1,13 @@
public class Test {
public Test(Object a) {
}
public Test(int i) {
this(new Integer(i));
}
public Test(long l) {
this(new Long(l));
}
}
@@ -0,0 +1,44 @@
public class Autoboxing {
void method(int i) {
System.out.println("i = " + i);
}
void method(Integer integer) {
System.out.println("integer = " + integer);
}
void m1(Integer integer) { }
void m2(int i) { }
{
method(10);
method(new Integer(10));
m1(10);
m1(new Integer(10));
m2(10);
m2(new Integer(10));
}
}
public class Autoboxing1 {
void method(String s, int i) {
System.out.println("i = " + i);
}
void method(String s, Object o) {
System.out.println("integer = " + o);
}
{
method("abc", new Integer(10));
method("abc", 10);
}
}
class BoxingConflict {
public static void main(String[] args) {
add<error descr="Ambiguous method call: both 'BoxingConflict.add(long, Long)' and 'BoxingConflict.add(Long, Long)' match">(0L, 0L)</error>;
}
public static void add(long k, Long v) { }
public static void add(Long k, Long v) { }
}
@@ -0,0 +1,122 @@
class D implements I<I>{
}
class DT<T> implements I<T>{
}
interface I <T> {
}
<error descr="'I' cannot be inherited with different type arguments: 'I' and 'D'">class CCC extends D implements I<D></error> {
}
abstract class CCC2<T> extends DT<T> implements I<T> {
}
class a extends b<d, c> implements c<d, c<c,c>>, d<b<c<c,c>,d>> {}
public class b<K,V> implements c<K, c<V,V>> { }
interface c<K,V> extends d<b<V,K>> {}
interface d<K> {}
// extending final classes in bounds
class C<T extends String> {
<E extends Integer> void f() {}
}
class GenericExtendItself<T, U extends T>
{
GenericExtendItself<Object,Object> foo;
}
////////////////////
public abstract class ZZZZ<E> {
public abstract E getElement();
}
abstract class Z<E> extends ZZZZ<E> {}
class Z2 extends Z<Integer> {
public Integer getElement() {
return null;
}
}
/////////////////
class BaseC <E> {
E remove(){
return null;
}
}
class DerivedC extends BaseC<String> {
public String remove() {
String s = super.remove();
return null;
}
}
/// raw in the multiple supers
interface Int<T> {
AClass<T> f();
}
abstract class AClass<T> implements Int<T> {
public abstract AClass<T> f();
}
class MyClass extends AClass implements Int{
public AClass f() {
return null;
}
}
class A<T>{
A(){}
A(T t){}
{
new A<A>(new A()){};
}
}
//IDEADEV-4733: this overriding is OK
class Outer<T>
{
public class Inner
{
private final T t;
public Inner(T t) { this.t = t; }
public T getT() { return t; }
public String toString() { return t.toString(); }
}
}
class Other extends Outer<String>
{
public class Ither extends Outer<String>.Inner
{
public Ither()
{
super("hello"); //valid super constructor call
}
}
}
//end of //IDEADEV-4733
interface AI {
}
interface BI {
}
abstract class AbstractClass<T> {
AbstractClass(Class<T> clazz) {
}
}
class ConcreteClass extends AbstractClass<AI> {
ConcreteClass() {
super(AI.class);
}
class InnerClass extends AbstractClass<BI> {
InnerClass() {
super(BI.class); //
}
}
}
///////////////////////
@@ -0,0 +1,21 @@
import java.util.TreeMap;
import java.util.HashMap;
import java.util.Map;
class Test {
boolean f () {
return false;
}
Boolean g (int i) {
//This is OK thanks to boxing f()
return i > 0 ? f () : null;
}
{
Object values = new Object();
//IDEADEV-1756: this should be OK
final Map<Object,Object> newValues = true ? new TreeMap<Object,Object>() : new HashMap<Object,Object>();
newValues.get(values);
}
}
@@ -0,0 +1,84 @@
import java.util.Collection;
import java.util.ArrayList;
interface YO<<warning descr="Type parameter 'T' is never used">T</warning>> {}
interface YO1 extends YO<String> {}
interface YO2 extends YO<Integer> {}
public class ConvertibleTest {
YO2 bar (YO1 s) {
return <error descr="Inconvertible types; cannot cast 'YO1' to 'YO2'">(YO2) s</error>;
}
}
//IDEA-1097
interface Interface1 {}
interface Interface2 {}
class Implementation implements Interface1 {}
public class InconvertibleTypesTest <E extends Interface2>
{
E thing;
public E getThing() {
return thing;
}
Implementation foo(InconvertibleTypesTest<? extends Interface1> i2) {
//This is a valid cast from intersection type
return (Implementation) i2.getThing();
}
}
class MyCollection extends ArrayList<Integer> {}
class Tester {
Collection<String> x(MyCollection l) {
return <error descr="Inconvertible types; cannot cast 'MyCollection' to 'java.util.Collection<java.lang.String>'">(Collection<String>) l</error>;
}
}
class IDEADEV3978 {
class Constructor<T> {
Class<T> getDeclaringClass() {
return null;
}
}
public static void foo(Constructor<?> constructor) {
if(constructor.getDeclaringClass() == String.class) { //captured wildcard is convertible
System.out.println("yep");
}
}
}
class C2<T> {
void f(T t) {
if (t instanceof Object[]) return;
}
}
class Casting {
void f(Object o)
{
if (o instanceof int[]) return;
Object obj1 = (Object)true; f(obj1);
Object ob = (Number)1; f(ob);
Object ob2 = (Object)1; f(ob2);
}
public static <T> T convert(Class<T> clazz, Object obj) {
if (obj == null) return null;
if (String[].class == clazz)
return <warning descr="Unchecked cast: 'java.lang.String[]' to 'T'">(T) parseArray(obj)</warning>;
return null;
}
private static String[] parseArray(Object obj) {
return obj.toString().split(",");
}
}
@@ -0,0 +1,21 @@
class W {
Object f() {
return 0;
}
}
class WW extends W {
String f() {
return null;
}
}
interface IQ {
void f();
}
<error descr="'f()' in 'WW' clashes with 'f()' in 'IQ'; attempting to use incompatible return type">class WWW extends WW implements IQ</error> {
}
@@ -0,0 +1,189 @@
enum Operation {
X;
static int s = 0;
public static final String constS = "";
Operation() {
int i = <error descr="It is illegal to access static member 's' from enum constructor or instance initializer">Operation.s</error>;
i = <error descr="It is illegal to access static member 's' from enum constructor or instance initializer">s</error>;
<error descr="It is illegal to access static member 's' from enum constructor or instance initializer">s</error> = 0;
final int x = Integer.MAX_VALUE;
String co = constS;
// TODO: unclear
//Operation o = X;
}
static {
int i = Operation.s;
i = s;
s = 0;
final int x = Integer.MAX_VALUE;
String co = constS;
// TODO: unclear
//Operation o = X;
}
{
int i = <error descr="It is illegal to access static member 's' from enum constructor or instance initializer">Operation.s</error>;
i = <error descr="It is illegal to access static member 's' from enum constructor or instance initializer">s</error>;
<error descr="It is illegal to access static member 's' from enum constructor or instance initializer">s</error> = 0;
final int x = Integer.MAX_VALUE;
String co = constS;
// TODO: unclear
//Operation o = X;
Operation ooo = <error descr="Enum types cannot be instantiated">new Operation()</error>;
}
<error descr="'values()' is already defined in 'Operation'">void values()</error> {}
void values(int i) {}
void valueOf() {}
<error descr="'valueOf(String)' is already defined in 'Operation'">void valueOf(String s)</error> {}
}
class exte extends <error descr="Cannot inherit from final 'Operation'">Operation</error> {
}
class use {
void f(Operation op) {
switch(op) {
case <error descr="An enum switch case label must be the unqualified name of an enumeration constant">Operation.X</error>: break;
}
switch(op) {
case X: break;
}
switch(op) {
case <error descr="Duplicate label 'X'">X</error>: break;
case <error descr="Duplicate label 'X'">X</error>: break;
}
}
}
enum pubCtr {
X(1);
<error descr="Modifier 'public' not allowed here">public</error> pubCtr(int i) {}
}
enum protCtr {
X(1);
<error descr="Modifier 'protected' not allowed here">protected</error> protCtr(int i) {}
}
<error descr="Modifier 'final' not allowed here">final</error> enum Fin { Y }
<error descr="Modifier 'abstract' not allowed here">abstract</error> enum Abstr { }
enum params<error descr="Enum may not have type parameters"><T></error> {
}
enum OurEnum {
A, B, C;
OurEnum() {
}
{
Enum<OurEnum> a = A;
OurEnum enumValue = B;
switch (enumValue) {
}
switch (enumValue) {
case A:
break;
}
}
}
enum TestEnum
{
A(<error descr="Illegal forward reference">B</error>), B(A);
TestEnum(TestEnum other) {
<error descr="Call to super is not allowed in enum constructor">super(null, 0)</error>;
}
}
<error descr="Class 'abstr' must either be declared abstract or implement abstract method 'run()' in 'Runnable'">enum abstr implements Runnable</error> {
}
//this one is OK, enum constants are checked instead of enum itself
enum abstr1 implements Runnable {
A {
public void run() {}
};
}
class X extends <error descr="Classes cannot directly extend 'java.lang.Enum'">Enum</error> {
public X(String name, int ordinal) {
super(name, ordinal);
}
}
enum StaticInEnumConstantInitializer {
AN {
<error descr="Inner classes cannot have static declarations">static</error> class s {
}
private <error descr="Inner classes cannot have static declarations">static</error> final String t = String.valueOf(1);
};
}
interface Barz {
void baz();
}
enum Fooz implements Barz {
<error descr="Class 'Fooz' must either be declared abstract or implement abstract method 'baz()' in 'Barz'">FOO</error>;
}
///////////////////////
class sss {
void f() {
<error descr="Enum must not be local">enum EEEE</error> { EE, YY };
}
}
//////////////////////
//This code is OK
enum PowerOfTen {
ONE(1),TEN(10),
HUNDRED(100) {
public String toString() {
return Integer.toString(super.val);
}
};
private final int val;
PowerOfTen(int val) {
this.val = val;
}
public String toString() {
return name().toLowerCase();
}
public static void main(String[] args) {
System.out.println(ONE + " " + TEN + " " + HUNDRED);
}
}
//IDEADEV-8192
enum MyEnum {
X1, X2;
private static MyEnum[] values = values();
public static void test() {
for (MyEnum e : values) { // values is colored red
e.toString();
}
}
}
//end of IDEADEV-8192
class EnumBugIDEADEV15333 {
public enum Type { one, to }
Type type = Type.one;
public void main() {
switch(type){
case one:
Object one = new Object();
}
}
}
@@ -0,0 +1,24 @@
<error descr="Modifier 'abstract' not allowed here">abstract</error> enum OurEnum {
A <error descr="Class 'Anonymous class derived from OurEnum' must either be declared abstract or implement abstract method 'foo()' in 'OurEnum'">{</error>
},
<error descr="'OurEnum' is abstract; cannot be instantiated">B</error>,
C {
void foo() {}
}
;
abstract void foo();
}
enum xxx {
<error descr="'xxx' is abstract; cannot be instantiated">X</error>,
Y <error descr="Class 'Anonymous class derived from xxx' must either be declared abstract or implement abstract method 'f()' in 'xxx'">{</error>
};
abstract void f();
}
enum ok {
X { void f() {} };
abstract void f();
}
@@ -0,0 +1,23 @@
class C <T extends Exception> {
void foo () throws T {}
void bar () {
<error descr="Unhandled exception: T">foo ();</error>
}
<T extends Error> void goo() {
try {
int i = 12;
} catch (<error descr="Cannot catch type parameters">T</error> ex) {
}
}
}
//IDEADEV-4169: no problem here
interface Blub {
public <E extends Throwable> void Switch() throws E;
}
class Blib implements Blub {
public <E extends Throwable> void Switch() throws E {
}
}
@@ -0,0 +1,20 @@
import java.util.*;
class Foo {
<T> void foo() {}
<T1 extends List, T2> void foo1() {}
void bar() {}
<T> void xyz(T l) {}
{
foo();
this.<String>foo();
this.<error descr="Wrong number of type arguments: 2; required: 1"><String, Integer></error>foo();
this.<error descr="Method 'bar()' does not have type parameters"><String></error>bar();
this.<error descr="Method 'bar()' does not have type parameters"><String, Integer></error>bar();
this.<<error descr="Type parameter 'java.lang.String' is not within its bound; should implement 'java.util.List'">String</error>, Integer>foo1();
this.<String>xyz<error descr="'xyz(java.lang.String)' in 'Foo' cannot be applied to '(java.lang.Integer)'">(Integer.valueOf("27"))</error>;
ArrayList list = new <error descr="Method 'ArrayList()' does not have type parameters"><String></error>ArrayList<String>();
}
}
@@ -0,0 +1,15 @@
import java.util.*;
class Foo {
interface Comparable<T> { }
static <T extends Comparable<T>> void sort(T t) {}
class C implements Comparable<C> {}
class D implements Comparable<String> {}
{
Foo.<C>sort(new C());
Foo.<<error descr="Type parameter 'Foo.D' is not within its bound; should implement 'Foo.Comparable<Foo.D>'">D</error>>sort(new D());
}
}
@@ -0,0 +1,29 @@
class a {
void f(int[] c) {
for (int i:c) {}
for (<error descr="Incompatible types. Found: 'int', required: 'char'">char i:c</error>) {}
for (double i:c) {}
double[] db = null;
for (<error descr="Incompatible types. Found: 'double', required: 'int'">int i:db</error>) {}
for (double i:db) {}
java.util.List list = null;
for (<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">String i:list</error>) {}
for (Object o:list) {}
java.util.List<Integer> ct = null;
for (Number n:ct) {}
for (Object n:ct) {}
for (Integer n:ct) {}
for (<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.lang.String'">String i:ct</error>) {}
for (<error descr="Incompatible types. Found: 'java.lang.Integer', required: 'java.util.List<java.lang.Integer>'">java.util.List<Integer> i:ct</error>) {}
Object o = null;
for (Object oi: (Iterable)o) {}
for (<error descr="Incompatible types. Found: 'double', required: 'int'">int i:db</error>) {
for (<error descr="Incompatible types. Found: 'java.lang.Object', required: 'int'">int p: list</error>) {}
}
}
}
@@ -0,0 +1,4 @@
class T extends Exception {}
class E<T> extends <error descr="Generic class may not extend 'java.lang.Throwable'">Error</error> {}
class M<T2 extends Exception> extends <error descr="Generic class may not extend 'java.lang.Throwable'">T</error> {}
class Ex<X,Y> extends <error descr="Generic class may not extend 'java.lang.Throwable'">Throwable</error> {}
@@ -0,0 +1,31 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/** @noinspection UnusedDeclaration*/
public class GenericsTest98 {
public static void main(String[] args) throws Exception{
List<Movable<? extends Serializable>> list = new ArrayList<Movable<? extends Serializable>> ();
Factory factory = Factory.newInstance();
// Doesn't compile, but Idea doesn't complain
Mover<? extends Serializable> mover = factory.getNew<error descr="'getNew(java.util.List<? extends Movable<T>>)' in 'Factory' cannot be applied to '(java.util.List<Movable<? extends java.io.Serializable>>)'">(list)</error>;
}
}
abstract class Factory {
public static Factory newInstance(){
return null;
}
// This should actually be
// public abstract <T extends Serializable> Mover<T> getNew (List<? extends Movable<? extends T>> source);
public abstract <T extends Serializable> Mover<T> getNew (List<? extends Movable<T>> source);
}
/** @noinspection UnusedDeclaration*/
interface Movable<T extends Serializable> extends Serializable {
}
/** @noinspection UnusedDeclaration*/
interface Mover<T extends Serializable> {
}
@@ -0,0 +1,29 @@
class ClassExt {
/** @noinspection UnusedDeclaration*/
public static <T, P1, P2> T newInstance(Class<T> clazz,
Class<? super P1> t1, P1 p1,
Class<? super P2> t2, P2 p2) {
return null;
}
}
abstract class TKey<T> {
protected abstract Class<T> getType();
}
class GoodIsRed6 {
public static <TK extends TKey<?>> TK createClone(TK tkey, String key) {
Class<TK> clazz = null;
return ClassExt.newInstance(clazz, String.class, key, Class.class, tkey.getType());
}
}
@@ -0,0 +1,29 @@
/** @noinspection UnusedDeclaration*/
class LimitedPool<T> {
private int capacity;
private final ObjectFactory<T> factory;
private Object[] storage;
private int index = 0;
public LimitedPool(final int capacity, ObjectFactory<T> factory) {
this.capacity = capacity;
this.factory = factory;
storage = new Object[capacity];
}
interface ObjectFactory<T> {
T create();
void cleanup(T t);
}
public T alloc() {
if (index >= capacity) return factory.create();
if (storage[index] == null) {
storage[index] = factory.create();
}
<error descr="Incompatible types. Found: 'java.lang.Object[]', required: 'T'">return storage;</error>
}
}
@@ -0,0 +1,18 @@
/** @noinspection UnusedDeclaration*/
interface TestIF2<T> extends TestIF3<T> {}
/** @noinspection UnusedDeclaration*/
interface TestIF<T extends TestIF2<? extends Test2>> {
void run(T o1);
}
/** @noinspection UnusedDeclaration*/
interface TestIF3<T> {}
class Test2 {}
class Test {
public void test(TestIF<?> testIF) {
testIF.run<error descr="'run(capture<? extends TestIF2<? extends Test2>>)' in 'TestIF' cannot be applied to '()'">()</error>;
}
}
@@ -0,0 +1,52 @@
class TestGenerics {
static interface EnumInterface {
public String getSomething();
}
static enum Enum1 implements EnumInterface {
A("alpha"),
B("beta"),
G("gamme"),
;
private String text;
Enum1(String text) {
this.text = text;
}
public String getSomething() {
return text;
}
}
static class TestBase<I extends Enum<I> & EnumInterface> {
protected final void add(Eval eval) {
eval.hashCode();
}
abstract class Eval {
private I enumI;
public Eval(I enumI) {
this.enumI = enumI;
}
public final void doSomething() {
System.out.println(enumI.getSomething());
}
}
}
class Test1 extends TestBase<Enum1> {
public Test1() {
add(new Eval(Enum1.A) {});
}
}
}
@@ -0,0 +1,29 @@
import java.util.ArrayList;
import java.util.Collections;
class SortTest<R extends Comparable<R>> implements Comparable<SortTest<R>> {
R r;
public SortTest(R r) {
this.r = r;
}
public int compareTo(SortTest<R> o) {
return r.compareTo(o.r);
}
public static void main(String[] args) {
ArrayList<SortTest<?>> list = new ArrayList<SortTest<?>>();
SortTest<?> t1 = new SortTest<String>("");
list.add(t1);
SortTest<?> t2 = new SortTest<Integer>(0);
list.add(t2);
<error descr="Inferred type 'SortTest<capture<?>>' for type parameter 'T' is not within its bound; should implement 'java.lang.Comparable<? super SortTest<?>>'">Collections.sort(list)</error>;
t1.compareTo<error descr="'compareTo(SortTest<capture<? extends java.lang.Comparable<capture<?>>>>)' in 'SortTest' cannot be applied to '(SortTest<capture<?>>)'">(t2)</error>;
//this should be OK
SortTest<?>[] arr = new SortTest<?>[0];
arr[0] = new SortTest<String>("");
}
}
@@ -0,0 +1,10 @@
import java.util.List;
import java.util.Arrays;
public class ZZZ {
List<Class<?>> f(Class<?>[] exceptionTypes) {
List<Class<?>> nd = Arrays.asList(exceptionTypes);
return nd;
}
}
@@ -0,0 +1,49 @@
import java.util.*;
interface TypesafeMap<BASE> {
@SuppressWarnings({"UnusedDeclaration"})
public interface Key<BASE,VALUE> { }
public <VALUE, KEY extends Key<BASE,VALUE>>
boolean has(Class<KEY> key);
public <VALUE, KEY extends Key<BASE,VALUE>>
VALUE get(Class<KEY> key);
public <VALUEBASE, VALUE extends VALUEBASE, KEY extends Key<BASE,VALUEBASE>>
VALUE set(Class<KEY> key, VALUE value);
public <VALUE, KEY extends Key<BASE,VALUE>>
VALUE remove(Class<KEY> key);
public Set<Class<?>> keySet();
public <VALUE, KEY extends Key<CoreMap, VALUE>>
boolean containsKey(Class<KEY> key);
}
interface CoreMap extends TypesafeMap<CoreMap> { }
interface CoreAnnotation<V>
extends TypesafeMap.Key<CoreMap, V> {
public Class<V> getType();
}
class CoreMaps {
public static <K,V> Map<K,V> toMap(Collection<CoreMap> coremaps,
Class<CoreAnnotation<K>> keyKey, Class<CoreAnnotation<V>> valueKey) {
Map<K,V> map = new HashMap<K,V>();
for (CoreMap cm : coremaps) {
map.put(cm.get(keyKey), cm.get(valueKey));
}
return map;
}
}
@@ -0,0 +1,17 @@
class Price {
public <PT extends Price> PT clone() {
return null;
}
}
class BondPrice extends Price {
public <PT extends BondPrice> PT clone() {
return null;
}
}
class User {
public static void main(String[] args) {
new BondPrice().clone<error descr="Ambiguous method call: both 'BondPrice.clone()' and 'Price.clone()' match">()</error>;
}
}
@@ -0,0 +1,74 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Comparator;
class TestIDEA
{
public static class Test1<Type extends List & Serializable>
{
public void process(Serializable s)
{
}
public void process(Type t)
{
}
}
public static class Test2 extends Test1<ArrayList>
{
public void process(Serializable s)
{
super.process(s);
}
public void process(ArrayList t)
{
super.process(t); // this call is OK resolving to parameterized method in super
}
}
public static void main(String[] args)
{
Test2 test=new Test2();
ArrayList list=new ArrayList();
test.process(list);
test.process((Serializable)list);
}
}
class Key<T> {
Object add(T v) {
return v;
}
}
class WKey<W, T> extends Key<T> {
W add(T v) {
return null;
}
}
class IBug {
public static <W, T> void addItem(WKey<W, T> key, T v) {
key.add(v); // --> demetra draw this in red, see attachment
}
}
//IDEADEV-7698
abstract class Collator implements Comparator<Object> {
public abstract int compare(String source, String target);
public int compare(Object o1, Object o2) {
return compare((String)o1, (String)o2);
}
public void foo(Collator c) {
c.compare("foo", "bar");
}
}
//end of //IDEADEV-7698
@@ -0,0 +1,15 @@
import java.lang.annotation.Annotation;
public @interface Foo {
String id();
}
class Bar implements Foo {
public String id() {
return null;
}
public Class<? extends Annotation> annotationType() {
return null;
}
}
@@ -0,0 +1,61 @@
import java.util.*;
class CLS {
static <V extends String> void bar (V v) {}
static void foo () {
bar<error descr="'bar(java.lang.String)' in 'CLS' cannot be applied to '(java.lang.Object)'">(new Object())</error>;
}
}
//////////////////////////////
public abstract class ZZZ<K> {
public abstract <T extends String> ZZZ<T> get();
}
class Z2<K> extends ZZZ<K> {
public <T extends String> Z2<T> get() {
return null;
}
void f() {
Z2 z2 = get();
}
}
/////////////////
abstract class LeastRecentlyUsedCache {
interface Callable<V> {
V call() throws Exception;
}
<E extends A> Callable<E> e(E e) {
return null;
}
<T extends B> Callable<T> f(boolean b, final T t) {
return b ? e(t) : new Callable<T>() {
public T call() throws Exception {
return t;
}
};
}
void ff() {
}
class A {}
class B extends A {}
}
//////////////////////////
public class BadCodeGreen<T, C extends Collection<? extends T>> {
public BadCodeGreen(C c, T t) {
c.add<error descr="'add(capture<? extends T>)' in 'java.util.Collection' cannot be applied to '(T)'">(t)</error>;
}
}
////////////////////////////
abstract class A {
public abstract <T extends List<?>> T create();
}
class B extends A {
public <T extends List<?>> T create() {
return null;
}
}
///////////////////////////
@@ -0,0 +1,2 @@
class C<T> extends <error descr="Class cannot inherit from its type parameter">T</error>
{}
@@ -0,0 +1,165 @@
import java.io.*;
import java.util.*;
class Test {
<T> List<T> asList (T... ts) {
ts.hashCode();
return null;
}
void foo() {
<error descr="Incompatible types. Found: 'java.util.List<java.lang.Class<? extends java.io.Serializable & java.lang.Comparable<?>>>', required: 'java.util.List<java.lang.Class<? extends java.io.Serializable>>'">List<Class<? extends Serializable>> l = this.asList(String.class, Integer.class);</error>
l.size();
List<? extends Object> objects = this.asList(new String(), new Integer(0));
objects.size();
}
}
//SUN BUG ID 5034571
interface I1 {
void i1();
}
class G1 <T extends I1> {
T get() { return null; }
}
interface I2 {
void i2();
}
class Main {
void f2(G1<? extends I2> g1) {
g1.get().i1(); // this should be OK
g1.get().i2(); // this should also be OK
}
}
//IDEADEV4200: this code is OK
interface I11 {
String i1();
}
interface I21 {
String i2();
}
interface A<T> {
T some();
}
interface B<T extends I11 & I21> extends A<T> {
}
class User {
public static void main(B<?> test) {
System.out.println(test.some().i1());
System.out.println(test.some().i2());
}
}
//end of IDEADEV4200
//IDEADEV-4214
interface Keyable<K> {
/**
* @return the key for the instance.
*/
public K getKey();
}
abstract class Date implements java.io.Serializable, Cloneable, Comparable<Date> {
}
class Maps {
public static class MapEntry<K, V> implements Map.Entry<K, V> {
K k;
V v;
public K getKey() {
return k;
}
public V getValue() {
return v;
}
public V setValue(V value) {
return v = value;
}
public MapEntry(K k, V v) {
this.k = k;
this.v = v;
}
}
public static <K, V> Map.Entry<K, V> entry(K key, V value) {
return new MapEntry<K, V>(key, value);
}
public static <K, V> Map<K, V> asMap(Map.Entry<? extends K, ? extends V> ... <warning descr="Parameter 'entries' is never used">entries</warning>) {
return null;
}
public static <K, V extends Keyable<K>> Map<K, V> asMap(V ... <warning descr="Parameter 'entries' is never used">entries</warning>) {
return null;
}
}
class Client {
void f(Date d) {
//this call should be OK
Maps.asMap(Maps.entry(fieldName(), "Test"),
Maps.entry(fieldName(), 1),
Maps.entry(fieldName(), d));
}
String fieldName() {
return null;
}
}
//end of IDEADEV-4214
class IDEADEV25515 {
static <T> List<T> asList (T... ts) {
ts.hashCode();
return null;
}
public static final
<error descr="Incompatible types. Found: 'java.util.List<java.lang.Class<? extends java.io.Serializable & java.lang.Comparable<?>>>', required: 'java.util.List<java.lang.Class<? extends java.io.Serializable>>'">List<Class<? extends Serializable>> SIMPLE_TYPES =
asList(String.class, Integer.class ,Long.class, Double.class, /*Date.class,*/
Boolean.class, Boolean.TYPE /*,String[].class */ /*,BigDecimal.class*/);</error>
public static final List<Class<? extends Serializable>> SIMPLE_TYPES_INFERRED =
asList(String.class, Integer.class ,Long.class, Double.class, /*Date.class,*/
Boolean.class, Boolean.TYPE ,String[].class /*,BigDecimal.class*/);
}
///////////////////////
class Axx {
<T extends Runnable> T a() {
<error descr="Incompatible types. Found: 'T', required: 'java.lang.String'">String s = a();</error>
s.hashCode();
return null;
}
}
///////////////
interface L {}
public class MaximalType {
public static <T> T getParentOfType(Class<? extends T>... classes) {
classes.hashCode();
return null;
}
{
getParentOfType(M2.class, M.class);
}
}
class M extends MaximalType implements L{}
class M2 extends MaximalType implements L{}
/////////////
@@ -0,0 +1,38 @@
import java.util.*;
interface Base {
}
class Derived implements Base {
}
class X {
void method(int i, Base b) { }
void method(int i, Derived b) { }
{
Derived d = new Derived();
method(10, d);
}
}
class Temp<T> {}
class A {
<error descr="'A(T)' clashes with 'A(T)'; both methods have same erasure">public <T extends Temp<String>> A(T list)</error> {}
public <T extends Temp<Integer>> A(T list) {}
}
class B {
public <T extends A> B(T list) {}
public <T extends Temp<Integer>> B(T list) {}
}
//////////////////////////////////////////
class IdeaBug {
static <T> T cloneMe(T arg) throws CloneNotSupportedException {
return (T) arg.<error descr="'clone()' has protected access in 'java.lang.Object'">clone</error>();
}
}
@@ -0,0 +1,16 @@
interface I {
void f();
}
interface II extends I {
<error descr="@Override is not allowed when implementing interface method">@Override</error>
void f();
}
class C implements I {
<error descr="@Override is not allowed when implementing interface method">@Override</error>
public void f() {
}
<error descr="Method does not override method from its superclass">@Override</error>
public void notoverride() {
}
}
@@ -0,0 +1,13 @@
interface I {
void f();
}
interface II extends I {
@Override
void f();
}
class C implements I {
@Override
public void f() {
}
}
@@ -0,0 +1,513 @@
import java.util.*;
abstract class C<T> {
abstract T f(int t);
void ff(T t) {}
C covariant1() { return null; }
C covariant2() { return null; }
<A> A get() { return null; }
}
abstract class D<U> extends C<C<U>> {
abstract <error descr="'f(int)' in 'D' clashes with 'f(int)' in 'C'; attempting to use incompatible return type">U</error> f(int t);
// overloaded, not overrridden
int ff(int u) { return 0; }
<error descr="'ff(C<U>)' in 'D' clashes with 'ff(T)' in 'C'; attempting to use incompatible return type">int</error> ff(C<U> u) {
return 0;
}
<error descr="'covariant1()' in 'D' clashes with 'covariant1()' in 'C'; attempting to use incompatible return type">Object</error> covariant1() { return null; }
D covariant2() { return null; }
<A> A get() { return null; }
}
abstract class C1<T> {
abstract T f(int t);
}
abstract class D1<U> extends C1<C1<U>> {
abstract C1<U> f(int i);
}
class CC<T> {
CC<Integer> f() { return null; }
CC<Integer> f2() { return null; }
CC<Integer> f3() { return null; }
<K,V> K f(V v) { return null; }
int fPrimitive() { return 0; }
}
class DD<T> extends CC<T> {
<error descr="'f()' in 'DD' clashes with 'f()' in 'CC'; attempting to use incompatible return type">DD<String></error> f() { return null; }
DD<Integer> f2() { return null; }
CC f3() { return null; }
<P,O> <error descr="'f(O)' in 'DD' clashes with 'f(V)' in 'CC'; attempting to use incompatible return type">O</error> f(O o) { return null; }
// incompatible although assignable
<error descr="'fPrimitive()' in 'DD' clashes with 'fPrimitive()' in 'CC'; attempting to use incompatible return type">double</error> fPrimitive() { return 0; }
}
interface Gen<T> {
<K1 extends T> void f(Gen<K1> cc);
}
class Raw implements Gen {
public void f(Gen o) {
abstract class MyComparator<T> {
abstract int compare(T t, T t1);
}
// raw type implemetation
new MyComparator() {
public int compare(Object t, Object t1) {
return 0;
}
};
}
}
class Gen2<GT> implements Gen<GT> {
public <K2 extends GT> void f(Gen<K2> o) {}
}
////////////// ERASURE CONFLICT
class A1 <T> {
T id(T t) {
return t;
}
}
interface I1 <T> {
T id(T t);
}
class A2 <T> extends A1<String> {
<error descr="'id(T)' in 'A2' clashes with 'id(T)' in 'A1'; both methods have same erasure, yet neither overrides the other">T id(T t)</error> {
return t;
}
}
class A3 <T> extends A1<String> {
<error descr="'id(Object)' in 'A3' clashes with 'id(T)' in 'A1'; both methods have same erasure, yet neither overrides the other">Object id(Object o)</error> {
return o;
}
}
<error descr="'id(T)' in 'A1' clashes with 'id(T)' in 'I1'; both methods have same erasure, yet neither overrides the other">class A4 extends A1<String> implements I1<Integer></error> {
String id(String t)
{ return null;}
public Integer id(Integer i)
{ return null; }
}
interface II1 <T> {
T id(int t);
}
interface II2 <T> {
T id(int t);
}
abstract class A5 implements II1<Integer>, II2<Integer> {}
<error descr="'id(int)' in 'II2' clashes with 'id(int)' in 'II1'; methods have unrelated return types">abstract class A6 implements II1<Integer>, II2<String></error> {}
abstract class A7 implements II1<Number>, II2<Integer>{}
abstract class A8 implements II1<Integer>, II2<Number>{}
abstract class HasGenericMethods<T> {
abstract <P> void toArray(P[] p);
}
public class RawOverridesGenericMethods extends HasGenericMethods{
public void toArray(Object[] ps) {
}
}
class CloneTest {
interface A {
A dup();
}
interface B extends A {
B dup();
}
interface C extends A {
C dup();
}
interface D extends B, C {
D dup();
}
interface X extends C, B {
X dup();
}
interface E extends C,A {
E dup();
}
}
///////////////
class ArrBase {
C<String> getC() { return null; }
Object[] getO() { return null; }
}
class ArrTest extends ArrBase {
C getC() { return null; }
String[] getO() { return null; }
}
///////////
class BarIU {
public <B> B[] toArray(B[] ts) {
return null;
}
}
interface IU {
public <I> I[] toArray(I[] ts);
}
public class BarIUBarIU extends BarIU implements IU{
public <T> T[] toArray(T[] ts) {
return null;
}
}
//////////////////////
class MyIterator<T> {
}
class AAA <A> {
public MyIterator<A> iterator() {
return null;
}
}
interface III <I> {
MyIterator<I> iterator();
}
class CCC <T> extends AAA<T> implements III<T> {
public MyIterator<T> iterator() {
return null;
}
}
//////////////////////////////////
interface CloneCovariant {
CloneCovariant clone();
}
interface ICloneCovariant extends CloneCovariant {
}
interface Cmp<T> {
int compareTo (T t);
}
<error descr="Class 'Singleton' must either be declared abstract or implement abstract method 'compareTo(T)' in 'Cmp'">class Singleton<T1> implements Cmp<Singleton<T1>></error> {
public <T2> int compareTo(Singleton<T1> t1) {
return 0;
}
}
class e<V> {
<T> void u (T t) {}
}
class f extends e<String> {
//If we inherit by erasure, then no type parameters must be present
<error descr="'u(Object)' in 'f' clashes with 'u(T)' in 'e'; both methods have same erasure, yet neither overrides the other"><T> void u (Object o)</error> {}
}
//SCR 41593, the following overriding is valid
interface q {
q foo();
}
interface p {
p foo();
}
class r implements q, p {
public r foo() {
return null;
}
}
//IDEADEV-2255: this overriding is OK
class Example {
interface Property<T> {
T t();
}
public static void main(String[] args) {
new ValueChangeListener<Number>() {
public <E extends Number> void valueChanged(Property<E> parent, E oldValue, E newValue) {
}
};
}
interface ValueChangeListener<T> {
<E extends T> void valueChanged(Property<E> property, E oldValue, E newValue);
}
}
//IDEADEV-3310: there is no hiding("static overriding") in this code thus no return-type-substitutability should be checked
class BaseClass {}
class SubClass extends BaseClass {}
class BaseBugReport {
public static <T extends BaseClass>
java.util.Set<T> doSomething() {
return null;
}
}
class SubBugReport extends BaseBugReport {
public static <T extends SubClass>
java.util.Set<T> doSomething() {
return null;
}
}
class First<T extends Number> {
void m(T t) {
System.out.println("A: " + t);
}
}
class Second<S extends Integer> extends First<S> {
//@Override
void m(S t) {
System.out.println("B: " + t);
}
}
class Third extends Second<Integer> {
<error descr="'m(Number)' in 'Third' clashes with 'm(T)' in 'First'; both methods have same erasure, yet neither overrides the other">void m(Number t)</error> {
System.out.println("D#m(Number): " + t);
}
//@Override
void m(Integer t) {
System.out.println("D#m(Integer): " + t);
}
}
//IDEADEV-4587: this code is OK
interface SuperA<T, E extends Throwable> {
T method() throws E;
}
interface SuperB<T, E extends Throwable> {
T method() throws E;
}
interface MyInterface<T, E extends Throwable> extends SuperA<T, E>, SuperB<T, E> {
}
//IDEADEV-2832
class IDEADEV2832Test {
public static void main(String[] args) {
Listener<String> dl = new <error descr="'listen(T)' in 'Listener' clashes with 'listen(Object)' in 'Anonymous class derived from Listener'; both methods have same erasure, yet neither overrides the other">Listener<String></error>() {
public void listen(String obj) {
}
public void listen(Object obj) {
}
};
}
}
interface Listener<T> {
void listen(T obj);
}
//end of IDEADEV-2832
//IDEADEV-8393
class Super<A extends Collection> {
public String sameErasure(final List<?> arg)
{
System.out.println("Int list");
return null;
}
}
final class Manista extends Super<Collection> {
public Collection sameErasure(final List<String> arg) {
System.out.println("String list");
return null;
}
}
//end of IDEADEV-8393
///////////////////
public class Prim {
Object g() {
return null;
}
}
class SPrim extends Prim {
byte[] g() {
return null;
}
}
//IDEADEV-21921
interface TypeDispatcher<T,V> {
public <S extends T> void dispatch(Class<S> clazz, S obj);
}
class DefaultDispatcher<T,V> implements TypeDispatcher<T,V> {
public <S extends T> void dispatch(Class<S> clazz, S obj) {
}
}
interface Node {
}
class BubbleTypeDispatcher extends DefaultDispatcher<Node, String> {
}
//end of IDEADEV-21921
////////////////////////////////////////
public class Bug2 extends SmartList<Bug2> implements Places {
}
interface Places extends java.util.List<Bug2> {}
class SmartList<E> extends java.util.AbstractList<E>{
public E get(int index) {
return null;
}
public int size() {
return 0;
}
}
////////////////IDEADEV-23176
class ActionImplementation extends MyAbstractAction
{
public void actionPerformed()
{
throw new RuntimeException();
}
}
abstract class MyAbstractAction extends AbstractAction implements MyAction { }
interface MyAction extends Action, BoundBean { }
interface BoundBean {
void addPropertyChangeListener();
void removePropertyChangeListener();
}
interface Action extends ActionListener {
public void addPropertyChangeListener();
public void removePropertyChangeListener();
}
interface ActionListener {
public void actionPerformed();
}
abstract class AbstractAction implements Action{
public synchronized void addPropertyChangeListener() {
}
public synchronized void removePropertyChangeListener() {
}
}
//////////////////////////////
class A extends BaseBuild implements SRunningBuild{
}
interface Build {
boolean isPersonal();
}
class BaseBuild implements Build {
public boolean isPersonal() {
return false;
}
}
interface HistoryBuild {
boolean isPersonal();
}
interface SRunningBuild extends Build,HistoryBuild{ }
////////////////////////////////////
interface PsiReferenceExpression extends PsiElement, PsiJavaCodeReferenceElement{}
interface PsiJavaCodeReferenceElement extends Cloneable, PsiQualifiedReference{}
interface PsiQualifiedReference extends PsiElement {}
interface PsiElement {
String toString();
}
///////////////////////IDEADEV-24300 ////////////////////////
public class ActionContext<A extends ContextAction> {
}
public abstract class ContextAction<AC extends ActionContext> {
protected abstract void performAction(AC context);
}
public class OurAction extends TableContextAction<Object> {
protected void performAction(TableContext<Object> context) {
}
}
public class TableContext<TCP> extends ActionContext<TableContextAction<TCP>> {
}
public abstract class TableContextAction<RO> extends ContextAction<TableContext<RO>> {
}
///////////////////////////////IDEADEV-23176 /////////////////////
public interface MyListModel { }
public interface MyList {
Object get(int i);
int hashCode();
}
public interface MutableListModel extends MyListModel, MyList {
}
public class ListModelImpl {
public Object get(int i) {
return null;
}
}
public class MutableListModelImpl extends ListModelImpl implements MutableListModel {
}
///////////////////////////////////////////////////////////////
public class InheritanceBug {
interface A {
Object clone();
}
interface B {
}
interface C extends A, B {
}
class X implements C {
public Object clone() {
return null;
}
}
class Y extends X {
}
}
///////////////////////////////////////
class ideadev {
interface A {
A f();
}
interface B extends A {
B f();
}
interface C extends A,B {
}
class s implements C {
public <error descr="'f()' in 'ideadev.s' clashes with 'f()' in 'ideadev.B'; attempting to use incompatible return type">A</error> f() {
return null;
}
}
class sOk implements C {
public B f() {
return null;
}
}
}
@@ -0,0 +1,177 @@
import java.util.ArrayList;
class Reference<<warning descr="Type parameter 'T' is never used">T</warning>> {
}
class WeakReference<T> extends Reference<T> {
}
class Item<<warning descr="Type parameter 'Key' is never used">Key</warning>, T> extends WeakReference<T> {
{
Reference<T> ref = null;
Item item = (Item) ref;
equals(item);
}
}
// assign raw to generic are allowed
class a<E> {
void f(a<E> t){
t.hashCode();
}
}
class b {
a<b> f(a raw) {
a<?> unbound = raw;
raw = unbound;
a<Integer> generic = <warning descr="Unchecked assignment: 'a' to 'a<java.lang.Integer>'">raw</warning>;
<warning descr="Unchecked call to 'f(a<E>)' as a member of raw type 'a'">raw.f</warning>(raw);
<warning descr="Unchecked call to 'f(a<E>)' as a member of raw type 'a'">raw.f</warning>(generic);
generic.f(<warning descr="Unchecked assignment: 'a' to 'a<java.lang.Integer>'">raw</warning>);
generic.f(generic);
generic.f<error descr="'f(a<java.lang.Integer>)' in 'a' cannot be applied to '(a<java.lang.String>)'">(new a<String>())</error>;
generic = <warning descr="Unchecked assignment: 'a' to 'a<java.lang.Integer>'">raw</warning>;
return <warning descr="Unchecked assignment: 'a' to 'a<b>'">raw</warning>;
}
}
class List<T> {
<V> V[] toArray (V[] vs) { return vs; }
void add(T t) {
t.hashCode();
}
}
class c {
/*String[] f () {
List l = new List();
error descr="Incompatible types. Found: 'java.lang.Object[]', required: 'java.lang.String[]'">return l.toArray (new String[0]);</error
}*/
String[] g () {
List<String> l = new List<String>();
return l.toArray (new String[0]);
}
}
class d {
class Y <<warning descr="Type parameter 'T' is never used">T</warning>> {
}
class Z <<warning descr="Type parameter 'T' is never used">T</warning>> extends Y<Y> {
}
class Pair <X> {
void foo(Y<? extends X> y) {
y.hashCode();
}
}
Pair<Z> pair;
void bar(Y<? extends Y> y) {
pair.foo<error descr="'foo(d.Y<? extends d.Z>)' in 'd.Pair' cannot be applied to '(d.Y<capture<? extends d.Y>>)'">(y)</error>;
}
}
class e {
String foo () {
MyList myList = new MyList();
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">return myList.get(0);</error>
}
static class MyList<<warning descr="Type parameter 'T' is never used">T</warning>> extends ArrayList<String>{
}
}
class ccc {
static Comparable<? super ccc> f() {
return <warning descr="Unchecked assignment: 'java.lang.Comparable' to 'java.lang.Comparable<? super ccc>'">new Comparable () {
public int compareTo(final Object o) {
return 0;
}
}</warning>;
}
}
class ddd<COMP extends ddd> {
COMP comp;
ddd foo() {
return comp; //no unchecked warning is signalled here
}
}
class G1<T> {
T t;
}
class G2<T> {
T t;
static ArrayList<G1> f() {
return null;
}
}
class Inst {
static void f () {
G2<G1<String>> g2 = new G2<G1<String>>();
for (<warning descr="Unchecked assignment: 'G1' to 'G1<java.lang.String>'">G1<String> g1</warning> : g2.f()) {
g1.toString();
}
}
}
class A111<T> {
T t;
<V> V f(V v) {
return v;
}
String g(A111 a) {
//noinspection unchecked
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.String'">return a.f("");</error>
}
}
class A1 {
<V> V f(V v) {
return v;
}
}
class A11<T> extends A1 {
T t;
//this is OK, type parameters of base class are not raw
String s = new A11().f("");
}
//IDEADEV-26163
class Test1<X> {
X x;
java.util.ArrayList<Number> foo = new java.util.ArrayList<Number>();
public static Number foo() {
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'java.lang.Number'">return new Test1().foo.get(0);</error>
}
}
//end of IDEADEV-26163
/////////////// signatures in non-parameterized class are not erased
public class C3 {
public int get(Class<?> c) {
return 0;
}
}
class Cp<T> extends C3 {
public T i;
}
class C extends Cp/*<C>*/ {
@Override
public int get(Class<?> c) {
return 0;
}
}
//////////////
@@ -0,0 +1,271 @@
import java.util.*;
class Base<T> {
public void method(Base<?> base) { }
public void method1(Base<Base<?>> base) { }
public <V> Base<V> foo() { return null; }
public Base<?> bar() { return null; }
public Base<Base<?>> far() { return null; }
}
class Derived extends Base {
public void method(Base base) { }
public Base foo() { return null; }
public Base bar() { return null; }
}
class Derived1 extends Base {
<error descr="'method1(Base<String>)' in 'Derived1' clashes with 'method1(Base<Base<?>>)' in 'Base'; both methods have same erasure, yet neither overrides the other">public void method1(Base<String> base)</error> { }
public Base<String> far() { return null; } // Acceptable construct as of JDK 1.5 beta 2 may 2004
}
class X <T> {
public <V> void foo () {}
}
class YY extends X {
<error descr="'foo()' in 'YY' clashes with 'foo()' in 'X'; both methods have same erasure, yet neither overrides the other">public <V> void foo()</error> {}
}
interface List<Y> {
public <T> T[] toArray(T[] ts);
}
class AbstractList<Y> {
public <T> T[] toArray(T[] ts) {return null;}
}
//Signatures from List and AbstractList are equal
class ArrayList extends AbstractList implements List {}
//SCR 39485: the following overriding is OK
abstract class Doer {
abstract <X> void go(X x);
}
class MyList <X>
extends Doer {
X x;
<Y> void go(Y y) {}
}
class MyListRaw
extends MyList {
}
//See IDEADEV-1125
//The following two classes are OK
class A1 {
<T> void foo(T t) {}
}
class A2 extends A1 {
void foo(Object o) {}
}
//While these are not
class A3 {
void foo(Object o) {}
}
class A4 extends A3 {
<error descr="'foo(T)' in 'A4' clashes with 'foo(Object)' in 'A3'; both methods have same erasure, yet neither overrides the other"><T> void foo(T t)</error> {}
}
//This sibling override is OK
class A5 {
public void foo(Object o) {}
}
interface I1 {
<T> void foo(T t);
}
class A6 extends A5 implements I1 {}
//While this is not
class A7 {
public <T> void foo(T t) {}
}
interface I2 {
public void foo(Object o);
}
<error descr="Class 'A8' must either be declared abstract or implement abstract method 'foo(Object)' in 'I2'">class A8 extends A7 implements I2</error> {}
//IDEA-9321
abstract class MyMap<K, V> implements java.util.Map<K, V> {
public <error descr="'put(K, V)' in 'MyMap' clashes with 'put(K, V)' in 'java.util.Map'; attempting to use incompatible return type">Object</error> put(K key, V value) {
return null;
}
}
//end of IDEA-9321
abstract class AA <T> {
abstract void foo(T t);
}
abstract class BB<T> extends AA<BB> {
void foo(BB b) {}
}
class CC extends BB {
//foo is correctly seen from BB
}
class QQQ {}
abstract class GrandParent<T> {
public abstract void paint(T object);
}
class Parent<T extends QQQ> extends GrandParent<T> {
public void paint(T component) {
}
}
// this overriding should be OK
class Child2 extends Parent {
}
class IDEA16494 {
class Base<B> {
public List<B> elements() {
return null;
}
}
class Derived<T> extends Base<T[]> {
}
class MostDerived extends Derived {
public List<MostDerived[]> elements() {
return null;
}
}
}
class IDEA16494Original {
class Base<B> {
public List<B> elements() {
return null;
}
}
class Derived<T> extends Base<T> {
}
class MostDerived extends Derived {
public List<MostDerived> elements() {
return null;
}
}
}
class IDEADEV23176Example {
public abstract class AbstractBase<E> extends AbstractParent<E> implements Interface<E> {
}
public abstract class AbstractParent<E> {
public void Implemented(Collection<?> c) {
}
public abstract void mustImplement();
}
public class Baseclass extends AbstractBase implements Interface {
public void mustImplement() {
}
}
public interface Interface<E> {
void Implemented(Collection<?> c);
}
}
/** @noinspection UnusedDeclaration*/
class IDEADEV26185
{
public static abstract class SuperAbstract<Owner, Type>
{
public abstract Object foo(Type other);
}
public static abstract class HalfGenericSuper<Owner> extends SuperAbstract<Owner, String>
{
public abstract Object foo(String other);
}
public static abstract class AbstractImpl<Owner> extends HalfGenericSuper<Owner>
{
public Object foo(String other)
{
return null;
}
}
public static class Concrete extends AbstractImpl
{
}
}
class ideadev30090 {
abstract class MyBeanContext
implements MyListInterface/*<MyListMember>*/ {
public Object get(int index) {
return null;
}
}
interface MyListInterface<E extends MyListMember>
extends List<E> {
}
interface MyListMember {
void f();
}
}
//////////////////////////////////////////
class IDEADEV32421 {
interface InterfaceWithFoo {
Class<?> foo();
}
class ParentWithFoo implements InterfaceWithFoo {
public Class foo() {
return null;
}
}
class TestII extends ParentWithFoo implements InterfaceWithFoo {
}
}
class IDEADEV32421_TheOtherWay {
interface InterfaceWithFoo {
Class foo();
}
class ParentWithFoo implements InterfaceWithFoo {
public Class<?> foo() {
return null;
}
}
class TestII extends ParentWithFoo implements InterfaceWithFoo {
}
}
//////////////////////////////////////
class SBBug {
abstract class A<T> implements Comparable<A<T>> {}
class B extends A {
public int compareTo(Object o) {
return 0;
}
}
}
class SBBug2 {
abstract class A<T> implements Comparable<A<T>> {}
<error descr="Class 'B' must either be declared abstract or implement abstract method 'compareTo(T)' in 'Comparable'">class B extends A</error> {
public int compareTo(A o) {
return 0;
}
}
}
@@ -0,0 +1,128 @@
import java.util.*;
class C<T,U> {
C c1 = new C<error descr="Wrong number of type arguments: 1; required: 2"><Integer></error>();
C c2 = new C<error descr="Wrong number of type arguments: 3; required: 2"><Integer, Float, Object></error>();
Object o = new Object<error descr="Type 'java.lang.Object' does not have type parameters"><C></error>();
C c3 = new C();
C c4 = new C<Object, C>();
C<Integer, Float> c5 = new C<Integer, Float>();
}
class D<T extends C> {
{
new D<<error descr="Type parameter 'java.lang.Integer' is not within its bound; should extend 'C'">Integer</error>>();
new D<C>();
class CC extends C {};
new D<CC>();
new D<T>();
}
T field = new <error descr="Type parameter 'T' cannot be instantiated directly">T</error>();
T field2 = new <error descr="Type parameter 'T' cannot be instantiated directly">T</error>() { };
T[] array = new <error descr="Type parameter 'T' cannot be instantiated directly">T</error>[10];
}
class Primitives<T> {
Object a = new Primitives<<error descr="Type argument cannot be of primitive type">? extends int</error>>();
Object o = new Primitives<<error descr="Type argument cannot be of primitive type">int</error>>();
void f(Primitives<<error descr="Type argument cannot be of primitive type">boolean</error>> param) {
if (this instanceof Primitives<<error descr="Type argument cannot be of primitive type">double</error>>) {
return;
}
}
}
/////// calling super on generic bound class
public class Generic<T> {
Generic(T t){}
}
public class Bound extends Generic<String>{
public Bound(String s) {
super(s);
}
}
////
class Generic2<T1,T2> {
class A {}
class B {}
private <error descr="Incompatible types. Found: 'Generic2<java.lang.String,Generic2.B>', required: 'Generic2<java.lang.String,Generic2.A>'">Generic2<String, A> map = new Generic2<String,B>();</error>
{
<error descr="Incompatible types. Found: 'Generic2<java.lang.String,java.lang.String>', required: 'Generic2<java.lang.String,Generic2.A>'">map = new Generic2<String,String>()</error>;
map = new Generic2<String,A>();
}
}
class DummyList<T> {}
abstract class GenericTest3 implements DummyList<<error descr="No wildcard expected">? extends String</error>> {
DummyList<DummyList<? extends DummyList>> l;
<T> void foo () {}
void bar () {
this.<DummyList<? extends DummyList>>foo();
DummyList<DummyList<? super String>>[] l = <error descr="Generic array creation">new DummyList<DummyList<? super String>>[0]</error>;
DummyList<String>[] l1 = <error descr="Generic array creation">{}</error>;
}
public <T> T[] getComponents (Class<T> baseInterfaceClass) {
T[] ts = <error descr="Generic array creation">{}</error>;
return ts;
}
}
class mylist<T> {}
class myAList<T> extends mylist<T> {
{
mylist<String> l = <error descr="Inconvertible types; cannot cast 'myAList<java.lang.Integer>' to 'mylist<java.lang.String>'">(mylist<String>) new myAList<Integer>()</error>;
boolean b = <error descr="Operator '==' cannot be applied to 'myAList<java.lang.Integer>','myAList<java.lang.String>'">new myAList<Integer>() == new myAList<String>()</error>;
if (l instanceof <error descr="Illegal generic type for instanceof">myAList<String></error>);
Object o = new Object();
if (o instanceof <error descr="Class or array expected">T</error>);
}
Class<T> foo (Class<T> clazz) {
Class<String> clazz1 = (Class<String>)clazz; //Should be unchecked warning
return <error descr="Cannot select from a type variable">T</error>.class;
}
}
class testDup<T, <error descr="Duplicate type parameter: 'T'">T</error>> { // CAN IT BE HIGHLIGHTED? b
public <T, <error descr="Duplicate type parameter: 'T'">T</error>> void foo() { // CAN IT BE HIGHLIGHTED?
}
}
class aaaa {
{
<error descr="Incompatible types. Found: 'java.lang.Class<java.lang.String>', required: 'java.lang.Class<? super java.lang.Object>'">Class<? super Object> c = String.class;</error>
}
}
//IDEADEV-6103: this code is OK
class Foo {
mylist<Test> foo;
public Foo(mylist<Test> foo) {
this.foo = foo;
}
public Foo() {
this(new mylist<Test>());
}
private class Test {
}
}
//end of IDEADEV-6103
class IDontCompile {
Map<error descr="Cannot select static class 'java.util.Map.Entry' from parameterized type"><?, ?></error>.Entry map;
}
abstract class GenericTest99<E extends Enum<E>> {
GenericTest99<<error descr="Type parameter 'java.lang.Enum' is not within its bound; should extend 'java.lang.Enum<java.lang.Enum>'">Enum</error>> local;
}
@@ -0,0 +1,34 @@
import java.util.*;
class SameSignatureTest {
<error descr="'sameErasure(List<String>)' clashes with 'sameErasure(List<Integer>)'; both methods have same erasure">public static void sameErasure(List<String> strings)</error> {
}
public static void sameErasure(List<Integer> integers) {
}
}
class CCC {
<error descr="'f(Object)' clashes with 'f(Object)'; both methods have same erasure"><T> void f(Object o)</error> {}
void f(Object o) {}
}
public class Test1 {
<error descr="'bug(String)' clashes with 'bug(String)'; both methods have same erasure">public void bug(String s)</error> {
}
public static <T> T bug(String s) {
return null;
}
}
////////////////////////////////
class Test {
<error descr="'test()' clashes with 'test()'; both methods have same erasure">public static <K, V> HashMap<K, V> test()</error> {
return new HashMap<K, V>();
}
public static String test() {
return "";
}
}
@@ -0,0 +1,53 @@
/** @noinspection UnusedDeclaration*/
interface Matcher<T> {
boolean matches(java.lang.Object object);
void _dont_implement_Matcher___instead_extend_BaseMatcher_();
}
interface ArgumentConstraintPhrases {
<T> T with(Matcher<T> matcher);
boolean with(Matcher<Boolean> matcher);
byte with(Matcher<Byte> matcher);
short with(Matcher<Short> matcher);
int with(Matcher<Integer> matcher);
long with(Matcher<Long> matcher);
float with(Matcher<Float> matcher);
double with(Matcher<Double> matcher);
}
class ExpectationGroupBuilder implements ArgumentConstraintPhrases {
public <T> T with(final Matcher<T> matcher) {
return null;
}
public boolean with(final Matcher<Boolean> matcher) {
return false;
}
public byte with(final Matcher<Byte> matcher) {
return 0;
}
public short with(final Matcher<Short> matcher) {
return 0;
}
public int with(final Matcher<Integer> matcher) {
return 0;
}
public long with(final Matcher<Long> matcher) {
return 0;
}
public float with(final Matcher<Float> matcher) {
return 0;
}
public double with(final Matcher<Double> matcher) {
return 0;
}
}
@@ -0,0 +1,16 @@
import static java.util.Arrays.asList;
import static java.util.Arrays.sort;
<warning descr="Unused import statement">import static java.util.Arrays.binarySearch;</warning>
public class StaticImports {
{
asList(new Object[]{});
}
void method() {
sort(new long[0]);
// sort< error descr="Cannot resolve method 'sort()'">()< /error>;
}
}
@@ -0,0 +1,18 @@
import java.util.Set;
interface Interface {
void method(Set<?> s);
}
class SuperClass implements Interface {
public void method(Set s) {
// do nothing
}
}
class SubClass extends SuperClass {
public void method(Set s) {
super.method(s); //ERROR: Abstract method 'method(Set<?>)' cannot be accessed directly
}
}
@@ -0,0 +1,21 @@
class GenericsTest {
static class SomeClass<U> {
public <T> T getX() {
return null;
}
public String f() {
return this.<String>getX();
}
}
public static void main(String[] args) {
String v1 = new SomeClass().<error descr="Type arguments given on a raw method"><String></error>getX();
String v2 = new SomeClass().f(); //
}
}
@@ -0,0 +1,95 @@
import java.io.FileNotFoundException;
import java.util.*;
interface PrivilegedExceptionAction <E extends Exception> {
void run() throws E;
}
class AccessController {
public static <E extends Exception> Object doPrivileged(PrivilegedExceptionAction<E> action) throws E {
return null;
}
}
class Test {
public static void main(String[] args) {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction<FileNotFoundException>() {
public void run() throws FileNotFoundException {
}
});
} catch (FileNotFoundException f) {
}
}
// @#@! mock JDK Class does not take params
// static <T> T create(Class<T> t) throws InstantiationException, IllegalAccessException {
// return t.newInstance();
// }
}
//IDEADEV-6390
class Printer<T> {
private final List<T> _elements;
private Printer(final Collection<? extends T> col) {
_elements = new ArrayList<T>(col);
}
public static <T> Printer<T> build(final Collection<? extends T> col) {
return new Printer<T>(col);
}
public static <T, S extends T> Printer<T> build(final S... elements) {
return new Printer<T>(Arrays.asList(elements));
}
public void print() {
for (final T element : _elements) {
System.out.println(element);
}
}
public static void main(final String[] args) {
final Printer<?> objects = build(Integer.valueOf(5), Boolean.TRUE, "A String!"); //this is OK
objects.print();
}
}
//end of IDEADEV-6390
//IDEADEV-6738
interface I1<P1 extends I1<P1,P2>, P2 extends I2<P1,P2>>{}
interface I2<P1 extends I1<P1,P2>, P2 extends I2<P1,P2>>{}
class C1 implements I1<C1,C2>{}
class C2 implements I2<C1,C2>{}
class U {
public static <P1 extends I1<P1,P2>, P2 extends I2<P1,P2>> P1 test(P1 p1) {
return null;
}
{
C1 c = new C1();
U.test(c); //this should be OK
}
}
//end of IDEADEV-6738
///////////////////////////////////
public class Err {
void f() {
Decl[] extensions = getExtensions(Decl.EXTENSION_POINT_NAME);
}
static <T> T[] getExtensions(List<T> tExtensionPointName) {
return null;
}
public static class Decl<K,V> {
public static List<Decl> EXTENSION_POINT_NAME = null;
}
}
/////////////////////////////////////
@@ -0,0 +1,33 @@
class C<T extends Runnable&<error descr="Interface expected here">Exception</error>,U> {
}
class Stuff<X extends Stuff & Runnable> {
<T, V extends T & <error descr="Type parameter cannot be followed by other bounds">Runnable</error>> T method(V v) {
return null;
}
<T extends X & <error descr="Type parameter cannot be followed by other bounds">Runnable</error> & <error descr="Type parameter cannot be followed by other bounds">Comparable</error>> void f(T t) {
}
<T extends Stuff & Runnable & Comparable> void f2(T t) {
}
<T extends Runnable & Comparable> void f3(T t) {
}
}
////////////////
public class TypeParameters {
class X {}
static <T extends X> void f(Class<T> t){}
static {
f(X.class);
}
}
class Typr {
<T extends TypeParameters.X> void f() {}
}
@@ -0,0 +1,58 @@
import java.util.*;
class X<<warning descr="Type parameter 'T' is never used">T</warning>> {
}
class XX<T> extends X<T> {
Object f(X<String> x) {
if (x != null) {
XX<String> xx = <warning descr="Unchecked cast: 'XX' to 'XX<java.lang.String>'">(XX<String>)new XX()</warning>;
return xx;
}
if (1 == 1) {
XX<String> xx = (XX<String>)x;
return xx;
}
return null;
}
}
class eee<COMP extends eee> {
COMP comp;
COMP foo() {
return <warning descr="Unchecked cast: 'eee' to 'COMP'">(COMP) new eee()</warning>;
}
}
class AllPredicate<T>
{
private List<Set<? super T>> lists;
public void e(AllPredicate that)
{
lists = <warning descr="Unchecked cast: 'java.util.List' to 'java.util.List<java.util.Set<? super T>>'">(List<Set<? super T>>)that.lists</warning>;
}
public static List<String> fff() {
Collection<String> c = new ArrayList<String>();
return (List<String>) c; //not unchecked
}
public static Comparable<Object> ggg() {
Object time = new Object();
return <warning descr="Unchecked cast: 'java.lang.Object' to 'java.lang.Comparable<java.lang.Object>'">(Comparable<Object>) time</warning>;
}
public static void foo(SortedMap<?, ?> sourceSortedMap) {
new TreeMap<Object, Object>(<warning descr="Unchecked cast: 'java.util.Comparator<capture<? super capture<?>>>' to 'java.util.Comparator<? super java.lang.Object>'">(Comparator<? super Object>) sourceSortedMap.comparator()</warning>);
}
}
class K { }
class L extends K { }
class M {
public static <T extends K> L f(T t) {
return (L) t; //this should NOT generate unchecked cast
}
}
@@ -0,0 +1,45 @@
class List<T> { T t;}
class Base<T> {
List<T> getList(List<T> l) {
return null;
}
}
class Derived extends Base <String> {
<warning descr="Unchecked overriding: return type requires unchecked conversion. Found 'List', required 'List<java.lang.String>'">List</warning> getList(List<String> l) {
return null;
}
}
class A1 {
<T> T foo(T t) {
return null;
}
}
class A2 extends A1 {
<warning descr="Unchecked overriding: return type requires unchecked conversion. Found 'java.lang.Object', required 'T'">Object</warning> foo(Object o) {
return null;
}
}
//IDEADEV-15918
abstract class Outer<U> {
public abstract Inner m(U u);
public class Inner {
}
}
class Other extends Outer<Other> {
public Ither m(Other other) {
return new Ither();
}
public class Ither extends Inner {
}
}
//end of IDEADEV-15918
@@ -0,0 +1,11 @@
enum e {
A("xxx");
private String s;
e(String str) {
s = str;
}
public String getS() {
return s;
}
}
@@ -0,0 +1,33 @@
class clazz1 {
clazz1(int... args) { args = null; }
public static class Myclazz1 extends clazz1 {}
}
class AmbiguousReference {
void test() {
doSomething<error descr="Ambiguous method call: both 'AmbiguousReference.doSomething(String, Number...)' and 'AmbiguousReference.doSomething(Number...)' match">(null, 1)</error>;
}
void doSomething(String s, Number... n) {
s+=n;
}
void doSomething(Number... n) {
n.hashCode();
}
}
class OK {
protected void fff() {
find("");
}
public void find(String queryString) {
queryString.hashCode();
}
public void find(final String queryString, final Object... values) {
queryString.hashCode();
values.hashCode();
}
}
@@ -0,0 +1,246 @@
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
/**
* Created by IntelliJ IDEA.
* User: dsl
* Date: Mar 25, 2004
* Time: 8:08:44 PM
* To change this template use File | Settings | File Templates.
*/
public class VarianceTesting {
void method(List<? extends VarianceTesting> l) {
// l.add(new VarianceTesting());
l.add(null);
}
static void shuffle(Collection<?> c) {}
static class X<T> {
T field;
T[] arrayField;
T[] method() {return arrayField;};
void putAll(Collection<? super T> c) {}
}
void method1(List<? super VarianceTesting> l) {
List<? extends VarianceTesting> l1 = new ArrayList<VarianceTesting>();
l1.add<error descr="'add(capture<? extends VarianceTesting>)' in 'java.util.List' cannot be applied to '(VarianceTesting)'">(new VarianceTesting())</error>;
List<List<? extends VarianceTesting>> lll = null;
lll.add(l1);
X<? extends VarianceTesting> x = new X<VarianceTesting>();
VarianceTesting z = x.field;
VarianceTesting[] v = x.arrayField;
VarianceTesting v1 = x.arrayField[0];
<error descr="Incompatible types. Found: 'VarianceTesting', required: 'capture<? extends VarianceTesting>'">x.arrayField[0] = new VarianceTesting()</error>;
<error descr="Incompatible types. Found: 'VarianceTesting', required: 'capture<? extends VarianceTesting>'">x.field = new VarianceTesting()</error>;
VarianceTesting[] k = x.method();
k[0] = new VarianceTesting();
<error descr="Incompatible types. Found: 'VarianceTesting', required: 'capture<? extends VarianceTesting>'">x.method()[0] = new VarianceTesting()</error>;
<error descr="Incompatible types. Found: 'VarianceTesting[]', required: 'capture<? extends VarianceTesting>[]'">x.arrayField = new VarianceTesting[10]</error>;
l1.addAll<error descr="'addAll(java.util.Collection<? extends capture<? extends VarianceTesting>>)' in 'java.util.List' cannot be applied to '(java.util.ArrayList<VarianceTesting>)'">(new ArrayList<VarianceTesting>())</error>;
<error descr="Incompatible types. Found: 'java.util.ArrayList<java.lang.String>', required: 'java.util.List<? extends VarianceTesting>'">List<? extends VarianceTesting> l2 = new ArrayList<String>();</error>
List<? extends VarianceTesting> l3 = l2;
VarianceTesting t = l1.get(0);
l.add(new VarianceTesting());
l.add(null);
<error descr="Incompatible types. Found: 'java.lang.Object', required: 'VarianceTesting'">VarianceTesting t1 = l.get(0);</error>
X<? extends VarianceTesting> x1 = null;
x1.putAll(new ArrayList<VarianceTesting>());
List<?> unknownlist = l;
List<?> unknownlist1 = new ArrayList<VarianceTesting>();
List<?> unknownlist2 = new ArrayList<<error descr="Wildcard type '?' cannot be instantiated directly">?</error>>();
shuffle(l);
shuffle(new ArrayList<VarianceTesting>());
List<VarianceTesting> lllll = new ArrayList<VarianceTesting>();
lllll.removeAll(new ArrayList<String>());
}
}
class SuperTester <U> {
void go(Acceptor<? super U> acceptor, U u) {
acceptor.accept<error descr="'accept(SuperTester<capture<? super U>>, capture<? super U>)' in 'SuperTester.Acceptor' cannot be applied to '(SuperTester<U>, U)'">(this, u)</error>;
}
static class Acceptor <V> {
void accept(SuperTester<V> tester, V v) { }
}
}
class SCR40202 {
void foo(Map<?, String> map) {
for (<error descr="Incompatible types. Found: 'java.util.Iterator<java.util.Map.Entry<capture<?>,java.lang.String>>', required: 'java.util.Iterator<java.util.Map.Entry<?,java.lang.String>>'">Iterator<Map.Entry<?, String>> it = map.entrySet().iterator();</error> it.hasNext();) {
}
}
}
class CaptureTest {
static class Emum<T> {
T t;
public static <T extends Emum<T>> T valueOf(Class<T> enumType,
String name) {
return null;
}
}
void foo (Class<? extends Emum<CaptureTest>> clazz) {
<error descr="Inferred type '? extends CaptureTest.Emum<CaptureTest>' for type parameter 'T' is not within its bound; should extend 'CaptureTest.Emum<? extends CaptureTest.Emum<CaptureTest>>'">Emum.valueOf(clazz, "CCC")</error>;
}
}
class SuperTest {
public List<List<? extends SuperTest>> waitingList;
public Comparator<List<?>> SIZE_COMPARATOR;
{
//This call has its type arguments inferred alright: T -> List<capture<? extends SuperTest>>
Collections.sort(waitingList, SIZE_COMPARATOR);
}
}
class Bug<A> {
static class B<C> {
}
static class D<E> {
B<E> f() {
return null;
}
}
<G extends A> void h(B<G> b) {
}
void foo(D<? extends A> d) {
h(d.f()); //This call is OK as a result of reopening captured wildcard for calling "h"
}
}
//IDEA-4215
class Case2 {
class A {}
class B extends A {}
Comparator<A> aComparator;
Case2() {
ArrayList<B> blist = new ArrayList<B>();
// this call is OK: T -> B
Collections.sort(blist, aComparator);
}
}
class S1 {
<T> void f(List<T> l1, T l2) {
}
void bar(List<? extends S1> k) {
f<error descr="'f(java.util.List<S1>, S1)' in 'S1' cannot be applied to '(java.util.List<capture<? extends S1>>, S1)'">(k, k.get(0))</error>;
}
}
class S2 {
<T> void f(List<T> l1, List<T> l2) {
}
void bar(List<? extends S2> k) {
f<error descr="'f(java.util.List<T>, java.util.List<T>)' in 'S2' cannot be applied to '(java.util.List<capture<? extends S2>>, java.util.List<capture<? extends S2>>)'">(k, k)</error>;
}
}
class S3 {
<T> void f(Map<T,T> l2) {
}
void bar(Map<? extends S3, ? extends S3> k) {
f<error descr="'f(java.util.Map<T,T>)' in 'S3' cannot be applied to '(java.util.Map<capture<? extends S3>,capture<? extends S3>>)'">(k)</error>;
}
}
class TypeBug {
private static class ValueHolder<T> {
public T value;
}
public static void main(final String[] args) {
List<ValueHolder<?>> multiList = new ArrayList<ValueHolder<?>>();
ValueHolder<Integer> intHolder = new ValueHolder<Integer>();
intHolder.value = 1;
ValueHolder<Double> doubleHolder = new ValueHolder<Double>();
doubleHolder.value = 1.5;
multiList.add(intHolder);
multiList.add(doubleHolder);
swapFirstTwoValues<error descr="'swapFirstTwoValues(java.util.List<TypeBug.ValueHolder<T>>)' in 'TypeBug' cannot be applied to '(java.util.List<TypeBug.ValueHolder<?>>)'">(multiList)</error>; //need to be highlighted
// this line causes a ClassCastException when checked.
Integer value = intHolder.value;
System.out.println(value);
}
private static <T> void swapFirstTwoValues(List<ValueHolder<T>> multiList) {
ValueHolder<T> intHolder = multiList.get(0);
ValueHolder<T> doubleHolder = multiList.get(1);
intHolder.value = doubleHolder.value;
}
}
class OtherBug {
public static void foo(List<? extends Foo> foos) {
final Comparator<Foo> comparator = createComparator();
Collections.sort(foos, comparator); //this call is OK
}
private static Comparator<Foo> createComparator() {
return null;
}
public interface Foo {
}
}
class OtherBug1 {
public static void foo(List<? super Foo> foos) {
final Comparator<Foo> comparator = createComparator();
Collections.sort<error descr="'sort(java.util.List<T>, java.util.Comparator<? super T>)' in 'java.util.Collections' cannot be applied to '(java.util.List<capture<? super OtherBug1.Foo>>, java.util.Comparator<OtherBug1.Foo>)'">(foos, comparator)</error>;
}
private static Comparator<Foo> createComparator() {
return null;
}
public interface Foo {
}
}
//IDEADEV-7187
class AA <B extends AA<B,C>, C extends AA<C, ?>>{}
//end of IDEADEV-7187
//IDEADEV-8697
class GenericTest99<E extends GenericTest99<E, F>,F> {
}
class GenericTest99D<E extends GenericTest99D<E>> extends GenericTest99<E,Double> {
}
class Use99<U extends GenericTest99<?,F>,F> {
}
class Use99n extends Use99<GenericTest99D<?>,Double> {
}
//end of IDEADEV-8697
@@ -0,0 +1,164 @@
import java.util.*;
class a {
public void printList(List<?> list) {
for (Iterator<?> i = list.iterator(); i.hasNext();) {
System.out.println(i.next().toString());
}
}
}
class b<<warning descr="Type parameter 'T' is never used">T</warning>> {
public interface Lst <E, Self extends Lst<E, Self>> {
Self subList(int fromIndex, int toIndex);
}
public static Lst<?, ?> foo(Lst<?, ?> lst) {
Lst<?, ?> myl = lst.subList(0, 2);
return myl;
}
}
class ThingUser <V> {
V v;
{
new ThingUser<<error descr="Wildcard type '?' cannot be instantiated directly">?</error>>() {
};
}
}
class SuperWildcardTest {
static void method(List<?> list) {
<error descr="Incompatible types. Found: 'java.util.List<capture<?>>', required: 'java.util.List<? super java.lang.String>'">List<? super String> l = list;</error>
l.size();
}
}
class IdeaDev4166 {
Map<String, Object> f( Map<String, ?> fieldsTemplate) {
return new HashMap<String, Object>( fieldsTemplate);
}
}
//IDEADEV-5816
class TwoD {
int x, y;
TwoD(int a, int b) {
x = a;
y = b;
}
}
// Three-dimensional coordinates.
class ThreeD extends TwoD {
int z;
ThreeD(int a, int b, int c) {
super(a, b);
z = c;
}
}
// Four-dimensional coordinates.
class FourD extends ThreeD {
int t;
FourD(int a, int b, int c, int d) {
super(a, b, c);
t = d;
}
}
// This class holds an array of coordinate objects.
class Coords<T extends TwoD> {
T[] coords;
Coords(T[] o) { coords = o; }
}
// Demonstrate a bounded wildcard.
class BoundedWildcard {
static void showXY(Coords<? extends TwoD> c) {
System.out.println("X Y Coordinates:");
for(int i=0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x + " " + c.coords[i].y);
}
System.out.println();
}
static void showXYZ(Coords<? extends ThreeD> c) {
System.out.println("X Y Z Coordinates:");
for(int i=0; i < c.coords.length; i++)
System.out.println(c.coords[i].x + " " +
c.coords[i].y + " " +
c.coords[i].z);
System.out.println();
}
static void showAll(Coords<? extends FourD> c) {
System.out.println("X Y Z T Coordinates:");
for(int i=0; i < c.coords.length; i++)
System.out.println(c.coords[i].x + " " +
c.coords[i].y + " " +
c.coords[i].z + " " +
c.coords[i].t);
System.out.println();
}
public static void main(String args[]) {
TwoD td[] = {
new TwoD(0, 0),
new TwoD(7, 9),
new TwoD(18, 4),
new TwoD(-1, -23)
};
Coords<TwoD> tdlocs = new Coords<TwoD>(td);
System.out.println("Contents of tdlocs.");
showXY(tdlocs); // OK, is a TwoD
showXYZ<error descr="'showXYZ(Coords<? extends ThreeD>)' in 'BoundedWildcard' cannot be applied to '(Coords<TwoD>)'">(tdlocs)</error>;
showAll<error descr="'showAll(Coords<? extends FourD>)' in 'BoundedWildcard' cannot be applied to '(Coords<TwoD>)'">(tdlocs)</error>;
// Now, create some FourD objects.
FourD fd[] = {
new FourD(1, 2, 3, 4),
new FourD(6, 8, 14, 8),
new FourD(22, 9, 4, 9),
new FourD(3, -2, -23, 17)
};
Coords<FourD> fdlocs = new Coords<FourD>(fd);
System.out.println("Contents of fdlocs.");
// These are all OK.
showXY(fdlocs);
showXYZ(fdlocs);
showAll(fdlocs);
}
}
//end of IDEADEV-5816
interface I33 {}
public class Q<T extends I33> {
T t;
<V extends I33> List<V> foo(Q<V> v) {
v.hashCode();
return null;
}
List<? extends I33> g (Q<?> q) {
return foo(q);
}
}
//IDEADEV-16628
class CollectionHelper {
public static <A> Collection<A> convertDown(Collection<? super A> collection) {
return collection == null ? null : null;
}
public static <A> Collection<A> convertUp(Collection<? extends A> collection) {
return collection == null ? null : null;
}
public static void main(String[] args) {
// Downcast examples
final Collection<Number> numbers1 = new ArrayList<Number>(1);
Collection<Integer> integers1 = CollectionHelper.convertDown(numbers1);
integers1.hashCode();
// Upcast example
final Collection<Integer> integers4 = new ArrayList<Integer>(1);
final Collection<Number> numbers4 = CollectionHelper.<Number>convertUp(integers4);
numbers4.hashCode();
}
}