File: FormatMethodInvocation.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (64 lines) | stat: -rw-r--r-- 2,265 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.io.ByteArrayOutputStream;
import java.io.Console;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Formatter;
import java.util.Locale;

public class FormatMethodInvocation {
    public static void main(String... p) {
        Formatter f = new Formatter();
        f.format("%d", 1337);
        f.format(Locale.GERMAN, "%d", 1337);
        // :: error: (argument.type.incompatible)
        f.format("%f", 1337);
        // :: error: (argument.type.incompatible)
        f.format(Locale.GERMAN, "%f", 1337);
        f.close();

        String.format("%d", 1337);
        String.format(Locale.GERMAN, "%d", 1337);
        // :: error: (argument.type.incompatible)
        String.format("%f", 1337);
        // :: error: (argument.type.incompatible)
        String.format(Locale.GERMAN, "%f", 1337);

        PrintWriter pw = new PrintWriter(new ByteArrayOutputStream());
        pw.format("%d", 1337);
        pw.format(Locale.GERMAN, "%d", 1337);
        pw.printf("%d", 1337);
        pw.printf(Locale.GERMAN, "%d", 1337);
        // :: error: (argument.type.incompatible)
        pw.format("%f", 1337);
        // :: error: (argument.type.incompatible)
        pw.format(Locale.GERMAN, "%f", 1337);
        // :: error: (argument.type.incompatible)
        pw.printf("%f", 1337);
        // :: error: (argument.type.incompatible)
        pw.printf(Locale.GERMAN, "%f", 1337);
        pw.close();

        PrintStream ps = System.out;
        ps.format("%d", 1337);
        ps.format(Locale.GERMAN, "%d", 1337);
        ps.printf("%d", 1337);
        ps.printf(Locale.GERMAN, "%d", 1337);
        // :: error: (argument.type.incompatible)
        ps.format("%f", 1337);
        // :: error: (argument.type.incompatible)
        ps.format(Locale.GERMAN, "%f", 1337);
        // :: error: (argument.type.incompatible)
        ps.printf("%f", 1337);
        // :: error: (argument.type.incompatible)
        ps.printf(Locale.GERMAN, "%f", 1337);
        ps.close();

        Console c = System.console();
        c.format("%d", 1337);
        c.printf("%d", 1337);
        // :: error: (argument.type.incompatible)
        c.format("%f", 1337);
        // :: error: (argument.type.incompatible)
        c.printf("%f", 1337);
    }
}