Closed GoogleCodeExporter closed 9 years ago
Many of these null pointer exceptions happen because getBoardPreferences isn't
checking if getTarget returns null before using it, and even if target exists,
returning null isn't an option since almost every use is a pointer to call
get() for
a specific board pref.
Just adding a couple checks in getBoardPreferences() eliminates the need for
many of
those try/catch blocks. It's only a few lines, changing from this:
static public Map<String, String> getBoardPreferences() {
return getTarget().getBoards().get(Preferences.get("board"));
}
to something like this:
static public Map<String, String> getBoardPreferences() {
Target target = getTarget();
if (target == null) return new LinkedHashMap();
Map map = getTarget().getBoards().get(Preferences.get("board"));
if (map == null) return new LinkedHashMap();
return map;
}
Of course, there are still some places not checking if
boardPreferences.get("something") is null, when they really should. For
example, in
Compiler, core should be checked, like this:
String core = boardPreferences.get("build.core");
if (core == null) {
Base.showWarning("No board selected", "Please choose a Board from the Tools
menu", null);
return false;
}
Original comment by paul.sto...@gmail.com
on 30 Apr 2010 at 7:41
Here is a patch
Original comment by paul.sto...@gmail.com
on 12 Jun 2010 at 5:59
Attachments:
Thanks for the patch. I modified it a bit and applied it.
Original comment by dmel...@gmail.com
on 12 Jun 2010 at 6:32
Original issue reported on code.google.com by
bnewbold
on 28 Apr 2010 at 4:13Attachments: