File: Issue2367.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 (34 lines) | stat: -rw-r--r-- 1,242 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
// Test case for issue #2367: http://tinyurl.com/cfissue/2367

public class Issue2367 {

    // Within the signed byte range

    byte b1 = 75;
    byte b2 = (byte) 75;
    byte b3 = (byte) -120;

    // Outside the signed byte range

    // Without the `(byte)` cast, all of these produce the following javac error:
    //   error: incompatible types: possible lossy conversion from int to byte
    // The Value Checker's `cast.unsafe` error is analogous and is desirable.

    // :: warning: (cast.unsafe)
    byte b4 = (byte) 139; // b4 == -117
    // :: warning: (cast.unsafe)
    byte b5 = (byte) -240;
    // :: warning: (cast.unsafe)
    byte b6 = (byte) 251;

    // Outside the signed byte range, but written as a hexadecimal literal.

    // As a special case, the Constant Value Checker could not issue a warning when a value is
    // within the signed byte range AND the value was specified in hexadecimal.
    // Such a special case is not yet implemented, and I don't see how to do so.
    // The program element "(byte) 0x8B" has already been converted to "(byte)139" by javac before
    // the Checker Framework gets access to it.

    // :: warning: (cast.unsafe)
    byte b7 = (byte) 0x8B; // 0x8B == 137, and b4 == -117
}