File tree Expand file tree Collapse file tree 5 files changed +33
-21
lines changed
src/main/java/org/scijava Expand file tree Collapse file tree 5 files changed +33
-21
lines changed Original file line number Diff line number Diff line change @@ -320,10 +320,7 @@ public <S extends Service> S service(final Class<S> c) {
320320 * service.
321321 */
322322 public Service service (final String className ) {
323- final Class <?> c = ClassUtils .loadClass (className );
324- if (c == null ) {
325- throw new IllegalArgumentException ("No such class: " + className );
326- }
323+ final Class <?> c = ClassUtils .loadClass (className , false );
327324 if (!Service .class .isAssignableFrom (c )) {
328325 throw new IllegalArgumentException ("Not a service class: " + c .getName ());
329326 }
Original file line number Diff line number Diff line change @@ -101,10 +101,13 @@ public String[] args() {
101101 @ Override
102102 public void exec () {
103103 try {
104- final Class <?> mainClass = ClassUtils .loadClass (className );
104+ final Class <?> mainClass = ClassUtils .loadClass (className , false );
105105 final Method main = mainClass .getMethod ("main" , String [].class );
106106 main .invoke (null , new Object [] { args });
107107 }
108+ catch (final IllegalArgumentException exc ) {
109+ if (log != null ) log .error (exc );
110+ }
108111 catch (final NoSuchMethodException exc ) {
109112 if (log != null ) {
110113 log .error ("No main method for class: " + className , exc );
Original file line number Diff line number Diff line change @@ -231,13 +231,20 @@ public URL getIconURL() {
231231 else return null ;
232232 }
233233 final String className = moduleInfo .getDelegateClassName ();
234- final Class <?> c = ClassUtils .loadClass (className );
235- if (c == null ) return null ;
236- final URL iconURL = c .getResource (iconPath );
237- if (iconURL == null ) {
238- if (log != null ) log .error ("Could not load icon: " + iconPath );
234+ try {
235+ final Class <?> c = ClassUtils .loadClass (className , false );
236+ final URL iconURL = c .getResource (iconPath );
237+ if (iconURL == null ) {
238+ if (log != null ) log .error ("Could not load icon: " + iconPath );
239+ }
240+ return iconURL ;
241+ }
242+ catch (final IllegalArgumentException exc ) {
243+ final String message = "Could not load icon for class: " + className ;
244+ if (log .isDebug ()) log .debug (message , exc );
245+ else log .error (message );
246+ return null ;
239247 }
240- return iconURL ;
241248 }
242249
243250 /**
Original file line number Diff line number Diff line change @@ -280,13 +280,15 @@ public String getClassName() {
280280 @ Override
281281 public Class <? extends PT > loadClass () throws InstantiableException {
282282 if (pluginClass == null ) {
283- final Class <?> c = ClassUtils .loadClass (className , classLoader );
284- if (c == null ) {
285- throw new InstantiableException ("Class not found: " + className );
283+ try {
284+ final Class <?> c = ClassUtils .loadClass (className , classLoader , false );
285+ @ SuppressWarnings ("unchecked" )
286+ final Class <? extends PT > typedClass = (Class <? extends PT >) c ;
287+ pluginClass = typedClass ;
288+ }
289+ catch (final IllegalArgumentException exc ) {
290+ throw new InstantiableException ("Class not found: " + className , exc );
286291 }
287- @ SuppressWarnings ("unchecked" )
288- final Class <? extends PT > typedClass = (Class <? extends PT >) c ;
289- pluginClass = typedClass ;
290292 }
291293
292294 return pluginClass ;
Original file line number Diff line number Diff line change @@ -255,13 +255,16 @@ public synchronized Class<?> lookupClass(final String alias)
255255 final Class <?> type = aliasMap ().get (alias );
256256 if (type != null ) return type ;
257257
258- final Class <?> c = ClassUtils . loadClass ( alias );
259- if ( c != null ) {
258+ try {
259+ final Class <?> c = ClassUtils . loadClass ( alias , false );
260260 aliasMap ().put (alias , c );
261261 return c ;
262262 }
263-
264- throw new ScriptException ("Unknown type: " + alias );
263+ catch (final IllegalArgumentException exc ) {
264+ final ScriptException se = new ScriptException ("Unknown type: " + alias );
265+ se .initCause (exc );
266+ throw se ;
267+ }
265268 }
266269
267270 // -- PTService methods --
You can’t perform that action at this time.
0 commit comments