Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShadowingClassLoader.doLoadClass(String) throws a StringIndexOutOfBoundsException during parsing packageName for the class under the default package(no package) [SPR-4443] #9121

Closed
spring-projects-issues opened this issue Feb 10, 2008 · 2 comments
Assignees
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

Comments

@spring-projects-issues
Copy link
Collaborator

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)

...
if (cls.getPackage() == null) {
	String packageName = name.substring(0, name.lastIndexOf('.'));
	definePackage(packageName, null, null, null, null, null, null, null);
}
...

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 10, 2008

Pengling Qian commented

see #7726, this same bug was not fixed, and exists in 2.0.6+.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, we need to check for the default package there. Thanks for spotting this!

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 2.5.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants