File: AssignmentDuringInitialization.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (42 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This test covers Issue345 at:
// https://github.com/typetools/checker-framework/issues/345
public class AssignmentDuringInitialization {
    String f1;
    String f2;

    String f3;
    String f4;

    String f5;
    String f6;

    {
        // :: error:  (assignment.type.incompatible)
        f1 = f2;
        f2 = f1;
        f2.toString(); // Null pointer exception here
    }

    public AssignmentDuringInitialization() {
        // :: error:  (assignment.type.incompatible)
        f3 = f4;
        f4 = f3;
        f4.toString(); // Null pointer exception here

        f5 = "hello";
        f6 = f5;
    }

    public void goodBehavior() {
        // this isn't a constructor or initializer
        // the receiver of this method should already be initialized
        // and therefore f1 and f2 should already be initialized
        f5 = f6;
        f6 = f5;
        f6.toString(); // No exception here
    }

    public static void main(String[] args) {
        AssignmentDuringInitialization a = new AssignmentDuringInitialization();
    }
}