4

I am having a problem where the YUI Compressor works fine in my IDE and even when I deploy tomcat using the maven goal tomcat:run, but throws a StringIndexOutOfBoundsException when I run the application as a WAR file:

java.lang.StringIndexOutOfBoundsException: String index out of range: 412
    at java.lang.String.substring(String.java:1934)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.printSourceString(JavaScriptCompressor.java:267)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.parse(JavaScriptCompressor.java:330)
    at com.yahoo.platform.yui.compressor.JavaScriptCompressor.<init>(JavaScriptCompressor.java:533)

Now, I know a lot of people have been reporting this problem, such as below: Yui compressor StringIndexOutOfBoundsException on jboss

You can find other people mentioning on other places on the web.

It has been suggested that you need to bundle the rhino files with the yui compressor in the same jar to avoid the classpath error.

I looked further, and I realized that Yahoo released version 2.4.7, which does this. So I included this new version into my project and made sure to remove the other jars, and I still get the same error.

How do I fix this?

Community
  • 1
  • 1
egervari
  • 22,372
  • 32
  • 121
  • 175
  • The above classpath arises as 'org/mozilla/javascript/Parser' class has different implementation in yuicompressor than rhino and particularly seen while in webapp build using maven. Issue could be resolved by following this blog link http://www.julienlecomte.net/blog/2008/10/80/ – Sandy Feb 11 '13 at 18:55

3 Answers3

4

If you are using maven build just exclusion rhino or remove js-1.7R2.jar / rhino-1.7R4.jar/ rhino-1.7R3.jar file from your classpath,

<dependency>
    <groupId>com.yahoo.platform.yui</groupId>
    <artifactId>yuicompressor</artifactId>
    <version>2.4.7</version>
    <exclusions>
        <exclusion>
            <artifactId>js</artifactId>
            <groupId>rhino</groupId>
        </exclusion>
    </exclusions>
</dependency>

Hope it will solve your problem.

Śhāhēēd
  • 1,812
  • 6
  • 23
  • 44
2

check your classpath and delete rhino-.jar(backup first),try it again.i solved the same problem after i removed rhino-.jar.

fafrei
  • 21
  • 2
1

This question should solve your problem, especially if you use maven:

Yui compressor StringIndexOutOfBoundsException on jboss

Community
  • 1
  • 1
lukewm
  • 21,433
  • 6
  • 26
  • 28