Bug 1145 : StringIndexOutOfBoundsException caused by import statements with no dots
Last modified: 2009-02-20 10:50




Status:
RESOLVED
Resolution:
FIXED -
Priority:
P2
Severity:
normal

 

Reporter:
PhiLhoČ
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-02-01 03:14
I have a sketch using 3 .pde files.
One of them have the line:

import quickhull3d;

I don't have a library named quickhull3d, it might be the issue, or not. I
have a quickhull3d.jar file which I plan to add to code folder, but not did
that yet. But that's the correct (given) package.

Anyway, when I try to run the (incomplete) sketch to see syntax errors, I
get the following stack trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1938)
at processing.app.Sketch.preprocess(Sketch.java:1414)
at processing.app.Sketch.build(Sketch.java:1471)
at processing.app.Sketch.compile(Sketch.java:1172)
at processing.app.Editor.handleRun(Editor.java:1564)
[...]

The culprit line is:

String entry = item.substring(0, item.lastIndexOf('.'));

Obviously, lastIndexOf is -1 because the import as no dot.

I think you should handle this case, and either behave correctly or output
a more friendly error message... :-)
Additional Comment #1 From PhiLhoČ 2009-02-02 04:01
After taking a coffee and looking better at the code, obviously my import
line should be:

import quickhull3d.*;

;-)

Yet my remark stands: having an out of bound exception in parse code isn't
very nice nor informative (I wondered where the faulty line was...).
So a friendly error message would be nice here. :-)
Additional Comment #2 From fry 2009-02-20 10:50
Fixed for 1.0.2.