Mvnrepository Yuicompressor's bug?

Source: Internet
Author: User

Yuicompressor is an excellent js&css compression tool. The system uses its 2.4.8 version of the jar to compress CSS and JS. The development phase is normal, but after the deployment to the test environment and the online environment, JS Compression failed, reportedIndexOutOfBoundsException。

看了下其逻辑,大致是先将待压缩的文本做预处理:识别文本中的function关键字、语句等特征部分,插入一些这些特征部分的标识符和长度信息;再根据这些信息构建压缩后的文本。比对了下测试环境和开发环境中预处理后的文本,发现测试环境中预处理后的文本在最末尾处的长度信息有误,导致substring的endIndex超出了文本长度。

测试环境和开发环境,源文本唯一的差别是字符串连接时使用的折行符,windows是回车换行,linux是回车,但经验判断不太可能是这个原因导致的。系统排除折行符的差异后,对比预处理后的文本字节码,发现字节码有差异。从源代码逻辑里,无法猜测导致差异的原因,故在源代码org.mozilla.javascript.Parser里加入了一些输出预处理过程的代码,发布到测试环境。。。之后发现测试环境一直报与新增代码相关的NoSuchField错误。很奇怪,又是开发环境不报错,测试环境报错。怀疑jar导致Parser类冲突了,搜索了下Parser类,发现Rhino(java版本的js解析器)也有一个Parser,而mvnrepository的yuicompressor是依赖了rhino的jar的。删除rhino的jar后,程序正常。(没有仔细阅读yuicompressor的源码,不知此举会不会带来其他一些bug)

Jars are loaded differently in different application servers, the development environment uses jetty, the Yuicompressor parser is loaded preferentially, and the test environment uses Tomcat, giving priority to loading rhino's parser. When using Yuicompressor javascriptcompressor to take compression js, error. The program cannot preset the order in which the jar is loaded.

Mvnrepository Yuicompressor's bug?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.