DATAJPA-407 - Fixes potential IndexOutOfBoundsException in ClasspathScanningPersistenceUnitPostProcessor.

So far, ClasspathScanningPersistenceUnitPostProcessor threw an IndexOutOfBoundsException on Windows as the OS-specific file separator doesn't match the forward slash used in the URI. This is fixed by modified scanForMappingFileLocations() to use '/' to build up the resource path.

Original pull request: #44.
This commit is contained in:
Thomas Darimont
2013-10-01 15:21:27 +02:00
committed by Oliver Gierke
parent 32f0f7830d
commit 18f89afa78
2 changed files with 13 additions and 3 deletions

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.jpa.support;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
@@ -122,8 +121,15 @@ public class ClasspathScanningPersistenceUnitPostProcessor implements Persistenc
return Collections.emptySet();
}
String basePackagePathComponent = basePackage.replace('.', File.separatorChar);
String path = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + basePackagePathComponent + File.separator
/*
* Note that we cannot use File.pathSeparator here since resourcePath uses a forward slash path ('/') separator
* being an URI, while basePackagePathComponent has system dependent separator (on windows it's the backslash separator).
*
* @see DATAJPA-407
*/
char slash = '/';
String basePackagePathComponent = basePackage.replace('.', slash);
String path = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + basePackagePathComponent + slash
+ mappingFileNamePattern;
Set<String> mappingFileUris = new HashSet<String>();
Resource[] scannedResources = new Resource[0];

View File

@@ -72,6 +72,9 @@ public class ClasspathScanningPersistenceUnitPostProcessorUnitTests {
verify(pui).addManagedClassName(SampleEntity.class.getName());
}
/**
* @see DATAJPA-407
*/
@Test
public void findsMappingFile() {
@@ -89,6 +92,7 @@ public class ClasspathScanningPersistenceUnitPostProcessorUnitTests {
/**
* @see DATAJPA-353
* @see DATAJPA-407
*/
@Test
public void shouldFindJpaMappingFilesFromMultipleLocationsOnClasspath() {