[GREENFOOT-367] NullPointerException hints
One of the most common run-time errors that beginners run into is surely NullPointerException. The recent BlueJ ticket to make stack traces clickable should help the user get to the source of the error more quickly, but it still might be at a stage where they don't understand it. I propose that we could add some help text that gives an automated hint as to what could be null. E.g. if you write:
{noformat} if (Greenfoot.getMouseInfo().getX() < 10 || foo.y > 100) {noformat}
Then it's technically achieveable to jump to that line, and offer the hint:
{noformat} NullPointerException One of: "Greenfoot.getMouseInfo()" or "foo" was null here. {noformat}
It's just a matter of looking up the line in the parse tree, and anything on the left-hand side of a method call or field access could have been null to cause the NPE. (Irritatingly, the JVM must know which of the items exactly was null, but it doesn't give back enough info for us to deduce this.)
Note: I'm only proposing this for Greenfoot, to help beginners along. I'm not sure if we'd want it in BlueJ.
Issue metadata
- Issue type: Task
- Priority: Medium