Skip to content

Commit 8e9f7a6

Browse files
Fix exception on compiler errors with column numbers
Error messages are detected and parsed using a regex. Part of this regex matches the optional column number. The code that handled this assumed that a missing column would result in less elements in the matches array, but a regex always results in one element per set of parenthesis in the regex, which will be null if no capture was made for that element. In practice, this meant that if no column was present in the error message, a NullPointerException would be raised. Furthermore, gcc 9 seems to have started outputting omitting column numbers (instead of printing 0) for some errors (such as unterminated #ifdef), which exposed this problem. This commit fixes this by simply using the fixed match numbers to take apart the regex match, and by checking for a null column number (all other captures are non-optional, so no need to check there).
1 parent 0dbff59 commit 8e9f7a6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

arduino-core/src/cc/arduino/Compiler.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,13 @@ public void message(String s) {
516516

517517
if (pieces != null) {
518518
String msg = "";
519-
int errorIdx = pieces.length - 1;
520-
String error = pieces[errorIdx];
521519
String filename = pieces[1];
522520
int line = PApplet.parseInt(pieces[2]);
523-
int col;
524-
if (errorIdx > 3) {
521+
int col = -1;
522+
if (pieces[3] != null) {
525523
col = PApplet.parseInt(pieces[3].substring(1));
526-
} else {
527-
col = -1;
528524
}
525+
String error = pieces[5];
529526

530527
if (error.trim().equals("SPI.h: No such file or directory")) {
531528
error = tr("Please import the SPI library from the Sketch > Import Library menu.");

0 commit comments

Comments
 (0)