RFR: 8232765: NullPointerException at Types.eraseNotNeeded() when compiling a class [v2]

Guoxiong Li gli at openjdk.java.net
Sat Apr 24 08:51:53 UTC 2021


On Fri, 23 Apr 2021 16:39:51 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> I believe here we don't need a new diagnostic - let's just reuse:

Fixed.

> The thing I'm a bit afraid, if we go down this path is that we will need to replicate all the override checks here - what if the method has the right signature but is private? It's still a bogus override.
>
> I could be fine if the answer was "this is the bare minimum we need to verify to make sure code generation doesn't crash". But I'd like to see a comment on the code stating exactly that.

I added the comment to state it and added several test cases to test these situations.

> Do we have a similar problem with AutoCloseable? E.g. a close() method returning something odd?

The check of AutoCloseable is right. I tested the following cases locally. The compiler didn't crash and the error messages were reasonable.


public class T {
    public void test(String[] args) {
        try (Test test = new Test()) {
            int a = 1;
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
}
class Test implements AutoCloseable {
    public int close() throws Exception {
        return 0;
    }
}



public class T {
    public void test(String[] args) {
        try (Test test = new Test()) {
            int a = 1;
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    class Test implements AutoCloseable {
        public int close() throws Exception {
            return 0;
        }
    }
}

-------------

PR: https://git.openjdk.java.net/jdk/pull/2099


More information about the compiler-dev mailing list