1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -114,9 +114,9 @@ public boolean requiresConfigInterface() {
114
114
public Object getScriptedObject (ScriptSource scriptSource , Class <?>... actualInterfaces )
115
115
throws IOException , ScriptCompilationException {
116
116
117
- try {
118
- Class <?> clazz ;
117
+ Class <?> clazz ;
119
118
119
+ try {
120
120
synchronized (this .scriptClassMonitor ) {
121
121
boolean requiresScriptEvaluation = (this .wasModifiedForTypeCheck && this .scriptClass == null );
122
122
this .wasModifiedForTypeCheck = false ;
@@ -140,43 +140,50 @@ public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInt
140
140
}
141
141
clazz = this .scriptClass ;
142
142
}
143
+ }
144
+ catch (EvalError ex ) {
145
+ this .scriptClass = null ;
146
+ throw new ScriptCompilationException (scriptSource , ex );
147
+ }
143
148
144
- if (clazz != null ) {
145
- // A Class: We need to create an instance for every call.
146
- try {
147
- return clazz .newInstance ();
148
- }
149
- catch (Throwable ex ) {
150
- throw new ScriptCompilationException (
151
- scriptSource , "Could not instantiate script class: " + clazz .getName (), ex );
152
- }
149
+ if (clazz != null ) {
150
+ // A Class: We need to create an instance for every call.
151
+ try {
152
+ return clazz .newInstance ();
153
+ }
154
+ catch (Throwable ex ) {
155
+ throw new ScriptCompilationException (
156
+ scriptSource , "Could not instantiate script class: " + clazz .getName (), ex );
153
157
}
154
- else {
155
- // Not a Class: We need to evaluate the script for every call.
158
+ }
159
+ else {
160
+ // Not a Class: We need to evaluate the script for every call.
161
+ try {
156
162
return BshScriptUtils .createBshObject (
157
163
scriptSource .getScriptAsString (), actualInterfaces , this .beanClassLoader );
158
164
}
159
- }
160
- catch ( EvalError ex ) {
161
- throw new ScriptCompilationException ( scriptSource , ex );
165
+ catch ( EvalError ex ) {
166
+ throw new ScriptCompilationException ( scriptSource , ex );
167
+ }
162
168
}
163
169
}
164
170
165
171
public Class <?> getScriptedObjectType (ScriptSource scriptSource )
166
172
throws IOException , ScriptCompilationException {
167
173
168
- try {
169
- synchronized ( this . scriptClassMonitor ) {
174
+ synchronized ( this . scriptClassMonitor ) {
175
+ try {
170
176
if (scriptSource .isModified ()) {
171
177
// New script content: Let's check whether it evaluates to a Class.
172
178
this .wasModifiedForTypeCheck = true ;
173
179
this .scriptClass = BshScriptUtils .determineBshObjectType (scriptSource .getScriptAsString ());
174
180
}
175
181
return this .scriptClass ;
176
182
}
177
- }
178
- catch (EvalError ex ) {
179
- throw new ScriptCompilationException (scriptSource , ex );
183
+ catch (EvalError ex ) {
184
+ this .scriptClass = null ;
185
+ throw new ScriptCompilationException (scriptSource , ex );
186
+ }
180
187
}
181
188
}
182
189
0 commit comments