Skip to content

Commit ea3c750

Browse files
committed
ReflectedUniverse: remove LogService usage
The LogService was only used for debugging, and only to emit the same information already thrown by the checked ReflectException. In other words: totally superfluous. The only really valid usage was in the main method, which is merely a test driver. That method uses System.out.println elsewhere, so using System.err.println for that one situation is more consistent anyway.
1 parent 2bc186d commit ea3c750

File tree

1 file changed

+3
-24
lines changed

1 file changed

+3
-24
lines changed

src/main/java/org/scijava/util/ReflectedUniverse.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343
import java.util.HashMap;
4444
import java.util.StringTokenizer;
4545

46-
import org.scijava.log.LogService;
47-
import org.scijava.log.StderrLogService;
48-
4946
/**
5047
* A general-purpose reflection wrapper class.
5148
* <p>
@@ -71,18 +68,11 @@ public class ReflectedUniverse {
7168
/** Whether to force our way past restrictive access modifiers. */
7269
private boolean force;
7370

74-
private final LogService log;
75-
7671
// -- Constructors --
7772

7873
/** Constructs a new reflected universe. */
7974
public ReflectedUniverse() {
80-
this(null, null);
81-
}
82-
83-
/** Constructs a new reflected universe. */
84-
public ReflectedUniverse(final LogService log) {
85-
this(null, log);
75+
this((ClassLoader) null);
8676
}
8777

8878
/**
@@ -96,13 +86,8 @@ public ReflectedUniverse(final URL[] urls) {
9686

9787
/** Constructs a new reflected universe that uses the given class loader. */
9888
public ReflectedUniverse(final ClassLoader loader) {
99-
this(loader, null);
100-
}
101-
102-
public ReflectedUniverse(final ClassLoader loader, final LogService log) {
10389
variables = new HashMap<String, Object>();
10490
this.loader = loader == null ? getClass().getClassLoader() : loader;
105-
this.log = log == null ? new StderrLogService() : log;
10691
}
10792

10893
// -- Utility methods --
@@ -166,18 +151,15 @@ public Object exec(String command) throws ReflectException {
166151
c = Class.forName(command, true, loader);
167152
}
168153
catch (final NoClassDefFoundError err) {
169-
log.debug("No such class: " + command, err);
170154
throw new ReflectException("No such class: " + command, err);
171155
}
172156
catch (final ClassNotFoundException exc) {
173-
log.debug("No such class: " + command, exc);
174157
throw new ReflectException("No such class: " + command, exc);
175158
}
176159
catch (final RuntimeException exc) {
177160
// HACK: workaround for bug in Apache Axis2
178161
final String msg = exc.getMessage();
179162
if (msg != null && msg.indexOf("ClassNotFound") < 0) throw exc;
180-
log.debug("No such class: " + command, exc);
181163
throw new ReflectException("No such class: " + command, exc);
182164
}
183165
setVar(varName, c);
@@ -280,7 +262,6 @@ else if (!(var instanceof Class<?>)) {
280262
exc = e;
281263
}
282264
if (exc != null) {
283-
log.debug("Cannot instantiate object", exc);
284265
throw new ReflectException("Cannot instantiate object", exc);
285266
}
286267
}
@@ -339,7 +320,6 @@ else if (!(var instanceof Class<?>)) {
339320
exc = e;
340321
}
341322
if (exc != null) {
342-
log.debug("Cannot execute method: " + methodName, exc);
343323
throw new ReflectException("Cannot execute method: " + methodName, exc);
344324
}
345325
}
@@ -450,15 +430,13 @@ else if (varName.matches("-?\\d*\\.\\d*")) {
450430
if (force) field.setAccessible(true);
451431
}
452432
catch (final NoSuchFieldException exc) {
453-
log.debug("No such field: " + varName, exc);
454433
throw new ReflectException("No such field: " + varName, exc);
455434
}
456435
Object fieldVal;
457436
try {
458437
fieldVal = field.get(var);
459438
}
460439
catch (final IllegalAccessException exc) {
461-
log.debug("Cannot get field value: " + varName, exc);
462440
throw new ReflectException("Cannot get field value: " + varName, exc);
463441
}
464442
return fieldVal;
@@ -501,7 +479,8 @@ public static void main(final String[] args) throws IOException {
501479
r.exec(line);
502480
}
503481
catch (final ReflectException exc) {
504-
r.log.debug("Could not execute '" + line + "'", exc);
482+
System.err.println("Could not execute '" + line + "':");
483+
exc.printStackTrace();
505484
}
506485
}
507486
System.out.println();

0 commit comments

Comments
 (0)