1

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.

5
  • Are we're supposed to diagnose this without seeing any source code? Commented Jul 19, 2010 at 14:33
  • I am trying to upsert a item managerService.save(item, tokenId); getting an exception in business layer public Item validateItem(final Item item) { try { final ValidatorFactory factory = Validation.byDefaultProvider().configure().traversableResolver(new CustomTraversableResolver()).buildValidatorFactory(); validator = factory.getValidator(); } catch (final Throwable e) { e.printStackTrace(); System.exit(0); } I can upsert when I run application on eclipse, issue is when I run as a commandline application through jar Commented Jul 19, 2010 at 15:01
  • Looks very interesting, taking in account the cause of exception(grepcode.com/file/repository.jboss.com/maven2/org.hibernate/…). Which OS and JRE do you use, where your Hibernate Validator's jar is placed, how do you put it into classpath? Commented Jul 19, 2010 at 15:12
  • I am using jdk 1.6, windows OS, I am using one jar to generate jar files below is the structure one-jar - lib(all validation jars, business.jar) -main.jar(where i have this method which has transactional attribute which calls my service layer) Commented Jul 19, 2010 at 15:19
  • I guess issue is with below two lines in org.hibernate.validator.util.Version class String pathToThisClass = 38 clazz.getResource( classFileName ).toString(); 39 String pathToManifest = pathToThisClass.substring( 0, pathToThisClass.indexOf( classFilePath ) - 1 ) 40 + "/META-INF/MANIFEST.MF"; As I am generating a jar file, clazz.getResource( classFileName ).toString() is returning a null, and hence throwing an exception. Is there any way I can avoid this Commented Jul 19, 2010 at 15:33

2 Answers 2

1

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?

Sign up to request clarification or add additional context in comments.

3 Comments

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: 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.
my aplogies, following is the scenario I am reading spring application context file final 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
0

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.