views:

71

answers:

2

I am getting following exception when trying to run my command line application:

java.lang.ExceptionInInitializerError
        at org.hibernate.validator.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:52)
        at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:43)
        at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -2
        at java.lang.String.substring(String.java:1937)
        at org.hibernate.validator.util.Version.<clinit>(Version.java:39)
        ... 34 more

Am I doing anything wrong? Please suggest.

A: 

So, as you use One-JAR, the problem probably is in incompatibility between One-JAR and Hibernate Validator. However, in the latest version of One-JAR (0.97) it works fine, therefore use the latest version.

axtavt
getting all sorts of exceptions while using latest one jar version, getting Illegal argument exception on invalid xml though there is valid xml, getting this exception when I am trying to read spring context.xml
praveen
+1  A: 

This is strange. I pasted the relevant parts of the static initialization block of o.h.v.u.Version in a class with a main and added some poor man's logging traces:

public class VersionTest {
    public static void main(String[] args) {
        Class clazz = org.hibernate.validator.util.Version.class;

        String classFileName = clazz.getSimpleName() + ".class";
        System.out.println(String.format("%-16s: %s", "classFileName", classFileName));

        String classFilePath = clazz.getCanonicalName().replace('.', '/') + ".class";
        System.out.println(String.format("%-16s: %s", "classFilePath", classFilePath));

        String pathToThisClass = clazz.getResource(classFileName).toString();
        System.out.println(String.format("%-16s: %s", "pathToThisClass", pathToThisClass));

        // This is line 39 of `org.hibernate.validator.util.Version`
        String pathToManifest = pathToThisClass.substring(0, pathToThisClass.indexOf(classFilePath) - 1)
            + "/META-INF/MANIFEST.MF";
        System.out.println(String.format("%-16s: %s", "pathToManifest", pathToManifest));
    }
}

And here the output I get when running it:

classFileName   : Version.class
classFilePath   : org/hibernate/validator/util/Version.class
pathToThisClass : jar:file:/home/pascal/.m2/repository/org/hibernate/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA.jar!/org/hibernate/validator/util/Version.class
pathToManifest  : jar:file:/home/pascal/.m2/repository/org/hibernate/hibernate-validator/4.0.2.GA/hibernate-validator-4.0.2.GA.jar!/META-INF/MANIFEST.MF

In your case, the StringIndexOutOfBoundsException: String index out of range: -2 suggests that:

pathToThisClass.indexOf( classFilePath )

is returning -1, making the pathToThisClass.substring(0, -2) call indeed erroneous.

And this means that org/hibernate/validator/util/Version.class is somehow not part of the pathToThisClass that you get. I don't have a full explanation but this must be related to the fact that you're using One-Jar.

Could you run the above test class and update your question with the output?

Pascal Thivent
By using one-jar version 0.96 , I am getting StringOutOfBoundException as pathtothisclassname generate different path but by using latest one jar 0.97 version I can overcome this error but other issue is when I am running latest one jar version I am getting InvalidArgumentException on InvalidXml whereas xml is valid, can I skip this validation on latest one jar version, please advise
praveen
@praveen: The provided "details" are not enough, I can't say anything. Please post traces, step to reproduce, etc. You need to help readers a bit.
Pascal Thivent
my aplogies, following is the scenarioI am reading spring application context filefinal ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml");my context.xml is<bean id="entityManagerFactory"class=".."><property name="jpaVendorAdapter"><bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"></bean>while reading "jpaVendorAdapter" from above xml, tries to read persistence_1_0.xsd from org/hibernate/ejb/persistence_1_0.xsd' which is throwing saxparserexception, i checked xsd file, its valid xml, am i doing anything wrong
praveen