| 1 |
// The test cases GenericNull, FieldAccess, and InferTypeArgs often fail together. |
| 2 |
// See the comments at GenericNull for some tips about what might be wrong. |
| 3 |
|
| 4 |
public class FieldAccess { |
| 5 |
class MyClass { |
| 6 |
|
| 7 |
Object field = new Object(); |
| 8 |
} |
| 9 |
|
| 10 |
class MyException extends RuntimeException { |
| 11 |
Object field = new Object(); |
| 12 |
} |
| 13 |
|
| 14 |
class MyExceptionA extends MyException {} |
| 15 |
|
| 16 |
class MyExceptionB extends MyException {} |
| 17 |
|
| 18 |
@SuppressWarnings("nullness") |
| 19 |
class MyGen<T extends MyClass> { |
| 20 |
T myClass = null; |
| 21 |
} |
| 22 |
|
| 23 |
void test(Object o, MyGen raw) { |
| 24 |
// Raw type field access: |
| 25 |
raw.myClass.field = new Object(); |
| 26 |
|
| 27 |
// Intersection type field access |
| 28 |
Object a = ((MyClass & Cloneable) o).field; |
| 29 |
try { |
| 30 |
} catch (MyExceptionA | MyExceptionB ex) { |
| 31 |
// Union type field access |
| 32 |
ex.field = new Object(); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
void classLiterals() { |
| 37 |
Class<?> c = byte.class; |
| 38 |
Class<?> d = void.class; |
| 39 |
} |
| 40 |
} |