Skip to content

Cannot add script after setting scripts in ResourceDatabasePopulator [SPR-11691] #16313

@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-11691 and commented

Status Quo

The setScripts() method in ResourceDatabasePopulator replaces the internal scripts array with a value returned from Arrays.asList() which is an unmodifiable List. Consequently, it is impossible to add additional scripts to a ResourceDatabasePopulator after setScripts() has been invoked.

For example, the following test fails with an UnsupportedOperationException.

public class ResourceDatabasePopulatorTests {

	private Resource script1 = resource("script1");
	private Resource script2 = resource("script2");
	private Resource script3 = resource("script3");

	@Test
	public void setScriptsAndThenAddScript() {
		ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
		databasePopulator.setScripts(script1, script2);

		// Throws UnsupportedOperationException
		databasePopulator.addScript(script3);
	}

	private Resource resource(String path) {
		return new ClassPathResource(path);
	}

}

Deliverables

  1. Ensure that scripts can be added to a ResourceDatabasePopulator after the setScripts() method has been invoked.

Affects: 3.2 GA

Referenced from: commits b4995f7

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions