BrokenErrorMessage.pde, whose content is irrelevant, and
SomeJavaCodeWithErrors.java:
public class SomeJavaCodeWithErrors // line 1
{ // line 2
public static int testMe() // line 3
{ // line 4
// provoking an error! // line 5
return asdflkj; // line 6, error, but it is reported be on line 3
}
}
When I hit the “play” button in the Processing-IDE, I, of course, do get an error: The variable "asdflkj" does not exist, but the source code location refers to line 3.
However, I would have expect the line number of the error not to be 6 and instead be 3.
What I am doing wrong? How I can get processing to report correct line numbers?
That is true, a stack frame is created when a function is executed, but that is not the case here because this compilation error will prevent the sketch being executed. If we add another error Processing reports both errors to be on line 3
public class SomeJavaCodeWithErrors // line 1
{ // line 2
public static int testMe() // line 3
{ // line 4
// provoking an error! // line 5
return asdflkj; // line 6, variable does not exist
} // line 7
// line 8
int xxx // line 9, missing semicolon
}
In Eclipse it highlights the two lines as having errors.
This is the result I’ve got from @quirin’s posted example using “javac” 21.0.2:
C:\Users\Gamer>javac SomeJavaCodeWithErrors.java
SomeJavaCodeWithErrors.java:6: error: cannot find symbol
return asdflkj; // line 6, error, but it is reported be on line 3
^
symbol: variable asdflkj
location: class SomeJavaCodeWithErrors
1 error
It infers error is at line 6; but it was 1st reported at line 3!
So Processing is half-right, and it also matches the behavior that all local variables are determined just before a function is actually run.
P.S.: I’ve moved the symbol asdflkj to a println() instead and it only reports that specific line now.
Perhaps b/c the unknown symbol was originally at a return statement, it’s also considered a function error too.
I am not sure whether it is due to the return statement. I get error for void-returning methods, as well as for statements outside methods.
public class SomeJavaCode
{
// asdoifn;// Uncomment to get an error on line 2
public void noReturn()
{
// Uncomment the following line to get an error on line 3
// sdjfas
System.out.println("Hello!");
}
public static int testMe()
{
int a = 3;
int b = 5;
// Uncomment the following line to get an error on line 3
//asdflkj;
int c = a + b;
return c;
}
public static int testMeAgain()
{
int a = 3;
int b = 5;
// Uncomment the following line to get an error on line 3
//asdflkj;
int c = a + b;
return c;
}
//asdoifn; // Uncomment to get an error on line 3
}
That’s the correct place to raise an issue. First search any open issues to see if anyone else has reported the same problem. I doubt it will be given a high priority because of the low impact on usability .