Buggy code:
public class ScriptFactoryPostProcessorTests extends TestCase { private static final String MESSAGE_TEXT = "Bingo" ; private static final String MESSENGER_BEAN_NAME = "messenger" ; private static final String PROCESSOR_BEAN_NAME = "processor" ; private static final String CHANGED_SCRIPT = "package<seq2seq4repair_space>org.springframework.scripting.groovy\n" + ( ( ( ( ( ( ( ( ( "import<seq2seq4repair_space>org.springframework.scripting.Messenger\n" + "class<seq2seq4repair_space>GroovyMessenger<seq2seq4repair_space>implements<seq2seq4repair_space>Messenger<seq2seq4repair_space>{\n" ) + "<seq2seq4repair_space>private<seq2seq4repair_space>String<seq2seq4repair_space>message<seq2seq4repair_space>=<seq2seq4repair_space>\"Bingo\"\n" ) + "<seq2seq4repair_space>public<seq2seq4repair_space>String<seq2seq4repair_space>getMessage()<seq2seq4repair_space>{\n" ) + "<seq2seq4repair_space>return<seq2seq4repair_space>\"\'\"<seq2seq4repair_space>+<seq2seq4repair_space>this.message<seq2seq4repair_space>+<seq2seq4repair_space>\"\'\"\n" ) + "<seq2seq4repair_space>}\n" ) + "<seq2seq4repair_space>public<seq2seq4repair_space>void<seq2seq4repair_space>setMessage(String<seq2seq4repair_space>message)<seq2seq4repair_space>{\n" ) + "<seq2seq4repair_space>this.message<seq2seq4repair_space>=<seq2seq4repair_space>message\n" ) + "<seq2seq4repair_space>}\n" ) + "}" ) ; private static final String EXPECTED_CHANGED_MESSAGE_TEXT = ( "'" + ( ScriptFactoryPostProcessorTests . MESSAGE_TEXT ) ) + "'" ; private static final int DEFAULT_SECONDS_TO_PAUSE = 1 ; private static final String DELEGATING_SCRIPT = "inline:package<seq2seq4repair_space>org.springframework.scripting;\n" + ( ( ( ( ( ( ( ( "class<seq2seq4repair_space>DelegatingMessenger<seq2seq4repair_space>implements<seq2seq4repair_space>Messenger<seq2seq4repair_space>{\n" + "<seq2seq4repair_space>private<seq2seq4repair_space>Messenger<seq2seq4repair_space>wrappedMessenger;\n" ) + "<seq2seq4repair_space>public<seq2seq4repair_space>String<seq2seq4repair_space>getMessage()<seq2seq4repair_space>{\n" ) + "<seq2seq4repair_space>return<seq2seq4repair_space>this.wrappedMessenger.getMessage()\n" ) + "<seq2seq4repair_space>}\n" ) + "<seq2seq4repair_space>public<seq2seq4repair_space>void<seq2seq4repair_space>setMessenger(Messenger<seq2seq4repair_space>wrappedMessenger)<seq2seq4repair_space>{\n" ) + "<seq2seq4repair_space>this.wrappedMessenger<seq2seq4repair_space>=<seq2seq4repair_space>wrappedMessenger\n" ) + "<seq2seq4repair_space>}\n" ) + "}" ) ; public void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation ( ) throws Exception { } public void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation ( ) throws Exception { } public void testChangeScriptWithRefreshableBeanFunctionality ( ) throws Exception { } public void testChangeScriptWithNoRefreshableBeanFunctionality ( ) throws Exception { } public void testRefreshedScriptReferencePropagatesToCollaborators ( ) throws Exception { } public void testReferencesAcrossAContainerHierarchy ( ) throws Exception { } public void testScriptHavingAReferenceToAnotherBean ( ) throws Exception { } public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall ( ) throws Exception { } public void testPrototypeScriptedBean ( ) throws Exception { GenericApplicationContext ctx = new GenericApplicationContext ( ) ; ctx . registerBeanDefinition ( "messenger" , BeanDefinitionBuilder . rootBeanDefinition ( StubMessenger . class ) . getBeanDefinition ( ) ) ; BeanDefinitionBuilder scriptedBeanBuilder = BeanDefinitionBuilder . rootBeanDefinition ( GroovyScriptFactory . class ) ; <START_BUG> scriptedBeanBuilder . setSingleton ( false ) ; <END_BUG> scriptedBeanBuilder . addConstructorArgValue ( ScriptFactoryPostProcessorTests . DELEGATING_SCRIPT ) ; scriptedBeanBuilder . addPropertyReference ( "messenger" , "messenger" ) ; final String BEAN_WITH_DEPENDENCY_NAME = "needsMessenger" ; ctx . registerBeanDefinition ( BEAN_WITH_DEPENDENCY_NAME , scriptedBeanBuilder . getBeanDefinition ( ) ) ; ctx . registerBeanDefinition ( "scriptProcessor" , ScriptFactoryPostProcessorTests . createScriptFactoryPostProcessor ( true ) ) ; ctx . refresh ( ) ; Messenger messenger1 = ( ( Messenger ) ( ctx . getBean ( BEAN_WITH_DEPENDENCY_NAME ) ) ) ; Messenger messenger2 = ( ( Messenger ) ( ctx . getBean ( BEAN_WITH_DEPENDENCY_NAME ) ) ) ; assertNotSame ( messenger1 , messenger2 ) ; } private static StaticScriptSource getScriptSource ( GenericApplicationContext ctx ) throws Exception { } private static BeanDefinition createScriptFactoryPostProcessor ( boolean isRefreshable ) { } private static BeanDefinition createScriptedGroovyBean ( ) { } private static void pauseToLetRefreshDelayKickIn ( int secondsToPause ) { } public static class DefaultMessengerService { private Messenger messenger ; public void setMessenger ( Messenger messenger ) { } public String getMessage ( ) { } } }

Fix:
scriptedBeanBuilder . setScope ( SCOPE_PROTOTYPE ) ;