@@ -136,16 +136,16 @@ public ScriptInfo(final Context context, final String path,
136136 setContext (context );
137137 this .path = path ;
138138
139- String script = null ;
139+ String contents = null ;
140140 if (reader != null ) {
141141 try {
142- script = getReaderContentsAsString (reader );
142+ contents = getReaderContentsAsString (reader );
143143 }
144144 catch (final IOException exc ) {
145145 log .error ("Error reading script: " + path , exc );
146146 }
147147 }
148- this . script = script ;
148+ script = contents ;
149149 }
150150
151151 // -- ScriptInfo methods --
@@ -231,14 +231,9 @@ public void parseParameters() {
231231 clearParameters ();
232232 appendReturnValue = true ;
233233
234- try {
235- final BufferedReader in ;
236- if (script == null ) {
237- in = new BufferedReader (new FileReader (getPath ()));
238- }
239- else {
240- in = getReader ();
241- }
234+ try (final BufferedReader in = script == null ? //
235+ new BufferedReader (new FileReader (getPath ())) : getReader ()) //
236+ {
242237 while (true ) {
243238 final String line = in .readLine ();
244239 if (line == null ) break ;
@@ -252,7 +247,6 @@ public void parseParameters() {
252247 }
253248 else if (line .matches (".*\\ w.*" )) break ;
254249 }
255- in .close ();
256250
257251 if (appendReturnValue ) addReturnValue ();
258252 }
@@ -384,7 +378,7 @@ private void parseParam(final String param,
384378
385379 /** Parses a comma-delimited list of {@code key=value} pairs into a map. */
386380 private Map <String , Object > parseAttrs (final String attrs ) {
387- return parser .parse (attrs ).asMap ();
381+ return parser .parse (attrs , false ).asMap ();
388382 }
389383
390384 private boolean isIOType (final String token ) {
@@ -456,7 +450,13 @@ private boolean is(final String key, final String desired) {
456450
457451 /** Super terse conversion helper method. */
458452 private <T > T as (final Object v , final Class <T > type ) {
459- return convertService .convert (v , type );
453+ final T converted = convertService .convert (v , type );
454+ if (converted != null ) return converted ;
455+ // NB: Attempt to convert via string.
456+ // This is useful in cases where a weird type of object came back
457+ // (e.g., org.scijava.sjep.eval.Unresolved), but which happens to have a
458+ // nice string representation which ultimately is expressible as the type.
459+ return convertService .convert (v .toString (), type );
460460 }
461461
462462 private <T > List <T > asList (final Object v , final Class <T > type ) {
0 commit comments