Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upScripted beans not updated after a script compilation error in getScriptedObjectType [SPR-14007] #18579
Comments
This comment has been minimized.
This comment has been minimized.
Anton Rokhmistrov commented I think come clarification is needed because it's not exactly the duplicate. The problem happens when groovy script is invalid (syntax error etc.). Then result of a call to the groovy bean is unpredictable, it can execute old version of the script or throw an exception depending on whether AbstractApplicationContext.getBeansOfType() was called or not. Example scenario:
Call to getScriptedObject
@Override
public Class<?> getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException {
....
if (this.scriptClass == null || scriptSource.isModified()) {
// New script content...
this.wasModifiedForTypeCheck = true;
this.scriptClass = getGroovyClassLoader().parseClass( [1]
scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
if (Script.class.isAssignableFrom(this.scriptClass)) {
// A Groovy script, probably creating an instance: let's execute it.
Object result = executeScript(scriptSource, this.scriptClass);
this.scriptResultClass = (result != null ? result.getClass() : null);
this.cachedResult = new CachedResultHolder(result);
}
else {
this.scriptResultClass = this.scriptClass;
}
}
....
} @Override
public Object getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces)
throws IOException, ScriptCompilationException {
if (this.scriptClass == null || scriptSource.isModified()) { [2]
// New script content...
this.scriptClass = getGroovyClassLoader().parseClass(
scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
if (Script.class.isAssignableFrom(this.scriptClass)) {
// A Groovy script, probably creating an instance: let's execute it.
Object result = executeScript(scriptSource, this.scriptClass);
this.scriptResultClass = (result != null ? result.getClass() : null);
return result;
}
else {
this.scriptResultClass = this.scriptClass;
}
}
scriptClassToExecute = this.scriptClass; [3]
} |
This comment has been minimized.
This comment has been minimized.
Juergen Hoeller commented Good point: We're resetting the |
Anton Rokhmistrov opened SPR-14007 and commented
This is a duplicate of #9034.
It does not work again because "ScriptFactory.requiresScriptedObjectRefresh(ScriptSource)" is not used in "GroovyScriptFactory#getScriptedObject(ScriptSource scriptSource, Class<?>... actualInterfaces)"
Affects: 3.2.16, 4.2.2, 4.2.5
Issue Links:
Referenced from: commits c2eb5e1, 0597ff1, 05ab769
Backported to: 3.2.17
2 votes, 4 watchers