ShadowingClassLoader.doLoadClass(String) throws a StringIndexOutOfBoundsException during parsing packageName for the class under the default package(no package) [SPR-4443] #9121
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Pengling Qian opened SPR-4443 and commented
I have created a test class extended AbstractJpaTests under the default package(i.e. no package). The exception is as follows:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1938)
at org.springframework.instrument.classloading.ShadowingClassLoader.doLoadClass(ShadowingClassLoader.java:194)
at org.springframework.instrument.classloading.ShadowingClassLoader.loadClass(ShadowingClassLoader.java:131)
at org.springframework.test.jpa.AbstractJpaTests.runBare(AbstractJpaTests.java:235)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
I have reviewd the source code, in method doLoadClass(string name)
The given name is a fully qualified class name, in this case, it is just a simple class name without any package path. So name.lastIndexOf('.') returned -1, and name.substring(0, -1) threw the StringIndexOutOfBoundsException, an unchecked exception.
Affects: 2.0.6, 2.0.7, 2.0.8, 2.5 final, 2.5.1
Backported to: 2.0.9
The text was updated successfully, but these errors were encountered: