Yui compressor StringIndexOutOfBoundsException on jboss
Asked Answered
A

4

11

When minimising yui with 2.4.6, I get this problem:

java.lang.StringIndexOutOfBoundsException: String index out of range: 232

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)

It works when started through my IDE but when deployed to jboss it doesn't. This place: http://yuilibrary.com/forum/viewtopic.php?p=20086 has some discussion of the same problem.

Apparently the issue is around org/mozilla/javascript/Parser being in the two jars that are pulled in from my maven config:

<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>

Is there any way I can solve this using maven exclusions etc. or by upgrading my version of YUI. It seems daft that it just doesn't work and I don't want to have to write a custom classloader.

Please help!

Antic answered 11/7, 2011 at 15:27 Comment(4)
I have this issue too! Bloody hell! Mine is tomcat 6 though.Blodgett
Did you manage to repackage OK? I ended up shoving most of the rhino source into my package in the end. I can probably make the package available on github if you have a couple of days?Antic
I've done the same repackaging, I'm waiting for working fix from YUI team side, but I doublt it will be fixed, taking the way they programm....Destruct
I filed a bug: github.com/yui/yuicompressor/issues/161Walkin
A
5

I solved this problem by repackaging yuicompressor myself to include most of the rhino source. See my reply to Howard M. Lewis Ship.

The repackaged source can be found here : http://viscri.co.uk/labs/tapestry/yuicompressor-rhino-bugfix-5.0.jar. Just add this to your pom:

<dependency>
   <groupId>yuicompressorbugfix</groupId>
   <artifactId>yuicompressor-rhino-bugfix</artifactId>
   <version>5.0</version>
</dependency>

If you don't run your own version of nexus, you'll have to install it on the machine that you want to build on. This is the command you need I think: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

You'll also need to exclude the yuicompressor version that tapestry pulls in:

<dependency>
   <groupId>org.apache.tapestry</groupId>
   <artifactId>tapestry-yuicompressor</artifactId>
   <version>5.3.2</version>
   <exclusions>
       <exclusion>
             <groupId>com.yahoo.platform.yui</groupId>
             <artifactId>yuicompressor</artifactId>
       </exclusion>
   </exclusions>

This should work.

Antic answered 1/8, 2011 at 16:56 Comment(1)
Yes, they pure little ant creatures are basing fully on sequence of libraries in class loader, which is so ill that I still can barely breathe writing it brrr! Them it is working because they use ant, on application server it's the opposite. I've done the packaging you've described and it works as it should.Destruct
P
8

Workaround: For JBoss AS 7.1.1.Final and YUICompressor 2.4.7

Exclude rhino from dependency:

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

Why? See https://github.com/greenlaw110/greenscript/pull/29#issuecomment-4017147

Note: if you have a rhino in classpath by some other way, so seems like you'll get this error again.

Perished answered 10/11, 2012 at 19:17 Comment(0)
A
5

I solved this problem by repackaging yuicompressor myself to include most of the rhino source. See my reply to Howard M. Lewis Ship.

The repackaged source can be found here : http://viscri.co.uk/labs/tapestry/yuicompressor-rhino-bugfix-5.0.jar. Just add this to your pom:

<dependency>
   <groupId>yuicompressorbugfix</groupId>
   <artifactId>yuicompressor-rhino-bugfix</artifactId>
   <version>5.0</version>
</dependency>

If you don't run your own version of nexus, you'll have to install it on the machine that you want to build on. This is the command you need I think: http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

You'll also need to exclude the yuicompressor version that tapestry pulls in:

<dependency>
   <groupId>org.apache.tapestry</groupId>
   <artifactId>tapestry-yuicompressor</artifactId>
   <version>5.3.2</version>
   <exclusions>
       <exclusion>
             <groupId>com.yahoo.platform.yui</groupId>
             <artifactId>yuicompressor</artifactId>
       </exclusion>
   </exclusions>

This should work.

Antic answered 1/8, 2011 at 16:56 Comment(1)
Yes, they pure little ant creatures are basing fully on sequence of libraries in class loader, which is so ill that I still can barely breathe writing it brrr! Them it is working because they use ant, on application server it's the opposite. I've done the packaging you've described and it works as it should.Destruct
W
1

The selected answer's (as of 9/26/2014) jar doesn't exist anymore.

So, I created a fork of yuicompressor where entire rhino package is embedded into the yuicompressor package and namespaced it under yui.

https://github.com/timothykim/yuicompressor

Just clone the repo and run ant to obtain the jar.

Hope this helps anyone else who stumbles unto this problem.

Walkin answered 26/9, 2014 at 23:20 Comment(0)
F
0

Really, you're having class loader problems in JBoss?

You're going to have to do some kind of exclusion on the competing rhino JAR file. Why is Rhino on the classpath? It may be an optional feature of JBoss you can turn off and avoid the conflict that way.

Fiat answered 12/7, 2011 at 21:19 Comment(2)
Rhino is on the classpath because the maven packaged yuicompressor depends on it. Basically yui overwrites a couple of rhino classes but not all of them, which results in either classNotFound exceptions if rhino is excluded, or the issue above if it isn't. I was going to send a mail to the tapestry mailing list about this, since I would have thought that using yui in tapestry 5.3 would result in the same problems. In the end I just munged rhino and yui together in my own custom jar.Antic
They describe the problem here: yuilibrary.com/projects/yuicompressor/ticket/2528114. They say it is solved, but I doubt it, taken the fact how this is written. The source pack downloaded today, at least, has nothing about it done.Destruct

© 2022 - 2024 — McMap. All rights reserved.