[hibernate-issues] [Hibernate-JIRA] Created: (HHH-7254) Using Eclipse's JarResrcLoader, an exception occurs: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Thomas Siegbert (JIRA)
noreply at atlassian.com
Tue Apr 17 07:41:48 EDT 2012
Using Eclipse's JarResrcLoader, an exception occurs: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
-----------------------------------------------------------------------------------------------------------------------------
Key: HHH-7254
URL: https://hibernate.onjira.com/browse/HHH-7254
Project: Hibernate ORM
Issue Type: Bug
Components: entity-manager
Affects Versions: 4.1.1, 3.6.10
Environment: Hibernate Core 3.6.10, Windows 7 Enterprise, Java SE 1.6.31, DB: Oracle 11.2.0.2, IDE: Eclipse Indigo
Reporter: Thomas Siegbert
Attachments: export_jar_in_jar.jar, export_libs_outside.rar, JarVisitorFactoryTest.java, log.txt
We have a project with a lot of jars. For delivering, we want to pack all jars and the binary code in one executable jar.
To build this executable jar, we use the export-functionality from Eclipse. In the wizard in Eclipse, we use the following option for "Library handling": "Package required libraries into generated JAR".
If I call this generated executable jar, I will get the following exception:
{quote}
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:378)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
at my.project.Main.main(Main.java:20)
... 5 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at org.hibernate.ejb.packaging.JarVisitorFactory.getJarURLFromURLEntry(JarVisitorFactory.java:55)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java: 344)
... 9 more
{quote}
If I do not pack all jars in one jar (instead, I use a sub-folder outside the jar containing all libs), the program works fine.
Probably, I have already identified the issue:
In the method "_org.hibernate.ejb.packaging.JarVisitorFactory.getJarURLFromURLEntry_" there is the following code line:
{quote} file = file.substring( 0, file.length() - entry.length() ); {quote}
This works fine, if _file.length()_ is equal or greater than _entry.length()_. In my case ("Jars-in-Jar") the variables in this method got the following content:
{quote}
file := META-INF/persistence.xml
entry := /META-INF/persistence.xml
url.toString := rsrc:META-INF/persistence.xml
{quote}
Thus, _file.length()_ < _entry.length()_ and the exception will be raised.
In our project, we fixed it as follows:
{quote} file = file.substring( 0, *Math.max( 0, file.length() - entry.length() )* ); {quote}
But this is only a suggestion and we cannot foresee any side effects (especially, we do not use an application server).
I attached the following files:
* JarVisitorFactoryTest.java -> Unit-Tests (which fails using 3.6.10)
* export_jar_in_jar.jar -> For reproduction (exception will raised). It is a small project.
* export_libs_outside.rar -> Please unpack. This version works fine, because the libs are not within the jar.
* log.txt -> stacktrace of the exception.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list