Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/main/java/com/googlecode/aviator/AviatorEvaluatorInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ public void enableSandboxMode() {
setOption(Options.ALLOWED_CLASS_SET, Collections.emptySet());
setOption(Options.ASSIGNABLE_ALLOWED_CLASS_SET, Collections.emptySet());
setOption(Options.EVAL_TIMEOUT_MS, 1000L);
this.removeModule(this.getModuleName(IoModule.class));
}

/**
Expand All @@ -489,17 +490,7 @@ public void enableSandboxMode() {
*/
public Env addModule(final Class<?> moduleClazz)
throws NoSuchMethodException, IllegalAccessException {
String namespace = moduleClazz.getSimpleName();

Import importAnt = moduleClazz.getAnnotation(Import.class);

if (importAnt != null) {
namespace = importAnt.ns();
if (namespace == null || namespace.isEmpty()
|| !ExpressionParser.isJavaIdentifier(namespace)) {
throw new IllegalArgumentException("Invalid namespace in Import annotation: " + namespace);
}
}
String namespace = getModuleName(moduleClazz);

Env exports = null;
synchronized (namespace.intern()) {
Expand All @@ -513,6 +504,21 @@ public Env addModule(final Class<?> moduleClazz)
}
}

private String getModuleName(final Class<?> moduleClazz) {
String namespace = moduleClazz.getSimpleName();

Import importAnt = moduleClazz.getAnnotation(Import.class);

if (importAnt != null) {
namespace = importAnt.ns();
if (namespace == null || namespace.isEmpty()
|| !ExpressionParser.isJavaIdentifier(namespace)) {
throw new IllegalArgumentException("Invalid namespace in Import annotation: " + namespace);
}
}
return namespace;
}

/**
* Remove a module by namespace name.
*
Expand Down
Loading