GateNLP / gate-core

The GATE Embedded core API and GATE Developer application
GNU Lesser General Public License v3.0
75 stars 29 forks source link

unhandled exception pop up for illegal character in path #111

Closed drj11 closed 4 years ago

drj11 commented 4 years ago

I got an unhandled exception pop-up when filling the pythonProgram initialisation parameter of the Python plugin (gateplugin-python). I'm creating an issue in gate-core because I assume that it's an issue with any ResourceReference type parameter.

It happens after I drag a file icon from my file browser into the parameter value field. And the press OK. Slightly to my surprise, dragging the icon into the value field appears to work (it may be the case that you have to select the value field to make it active) and looks like it's the same as pasting the full file:// URI for the file into the field. But when I press [OK] I get the popup.

unhandled-error

Output in message window:

java.lang.IllegalArgumentException: Illegal character in path at index 56: file:///home/ac1xdrj/prj/StanceClassifier/gate_stance.py 
    at java.net.URI.create(URI.java:852)
    at java.net.URI.resolve(URI.java:1036)
    at gate.creole.ResourceReference.<init>(ResourceReference.java:141)
    at gate.creole.Parameter.calculateValueFromString(Parameter.java:262)
    at gate.creole.AbstractResource.setParameterValue(AbstractResource.java:207)
    at gate.creole.AbstractResource.setParameterValues(AbstractResource.java:276)
    at gate.creole.AbstractResource.setParameterValues(AbstractResource.java:438)
    at gate.Factory.createResource(Factory.java:325)
    at gate.gui.NewResourceDialog$4.run(NewResourceDialog.java:270)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.URISyntaxException: Illegal character in path at index 56: file:///home/ac1xdrj/prj/StanceClassifier/gate_stance.py 
    at java.net.URI$Parser.fail(URI.java:2848)
    at java.net.URI$Parser.checkChars(URI.java:3021)
    at java.net.URI$Parser.parseHierarchical(URI.java:3105)
    at java.net.URI$Parser.parse(URI.java:3053)
    at java.net.URI.<init>(URI.java:588)
    at java.net.URI.create(URI.java:850)

I am investigating the characters more closely. Obviously a bit tricky as at least one of them is invisibly suspicious. The file itself has a perfectly ordinary name by the way.

greenwoodma commented 4 years ago

Which file browser and Java version are you trying this with? I just tried with nautilus and JDK9 and I can't seem to drop into that field.

ianroberts commented 4 years ago

If that is an accurate copy and paste of the stack trace and GitHub hasn't changed anything then the index 56 is a normal space character U+0020 that has been added after the end of the file name.

The drag and drop into the parameter field doesn't work for me on Mac but I know my machine does the same thing when I drag a file from Finder into the Terminal, it inserts the file path followed by a trailing space (which make perfect sense there as you're typically going to want to use the file name as an argument to something and don't want to accidentally glue two arguments together).

greenwoodma commented 4 years ago

Yes, I'd just come to the same conclusion. I suppose I could have the ResourceReference constructor trim the value before turning it into a URI as a space on the end is highly unlikely to ever be right (I would assume).

Although weirdly, I've just tried adding a space to the end of a filename and that doesn't throw an exception (was filling in sourceUrl for a document but the code should be the same)

johann-petrak commented 4 years ago

When I manually add a space at the end of a file:///something URL I do get the illegal argument exception.

In my case, just drag+drop to the input field does not work, but first clicking the input field and then doing the drag and drop does work. (Ubuntu, xfce window manager).

BTW, doing the same with the URL-typed entry field, e.g. for a document sourceUrl, the trailing space seems to get ignored.

greenwoodma commented 4 years ago

Ah, I missed that sourceUrl is still a URL (that's probably an issue itself). Sounds like I'm not doing a trim() somewhere in the resource reference stuff that I am with the URLs