summaryrefslogtreecommitdiffstats
path: root/tools/infer/test/autotest/src/main/java/Checkers.java
blob: f26170a471c0116e3d72629a1ee565677e0e1438 (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Checkers {
    public static void leak() {
        try {
            BufferedReader br = new BufferedReader(
                new FileReader(new File("some.txt"))
            );
        } catch (Exception e) {

        }
    }

    public static void error1() {
        String str = null;
        try {
            int x = str.length(); // Error: even if exception is caught
        } catch (NullPointerException e) {

        }
    }

    public static void error2() {
        String str = null;
        int x = str.length(); // Error: not checking for null
    }

}