使用 Java 1.8.0_251 转换 XSL 时发生致命错误 [英] Fatal Error when transforming a XSL with Java 1.8.0_251

查看:40
本文介绍了使用 Java 1.8.0_251 转换 XSL 时发生致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试转换样式表时,我收到来自 Java 1.8.0_251 的以下错误.然而,相同的样式表转换与 Java 1.8.0_241 没有任何问题.当行 tFactory.newTransformer(stylesheet); 时出现错误;被执行.

同样使用 xalan 2.7.2 而不是 Java 1.8.0._251 也能工作,但那个版本的 os xalan 真的很旧.

有人遇到过这种情况吗?如果是如何解决?

SimpleNotWorking04.xslhttps://drive.google.com/file/d/1pUiMvVtVBmBvCwfPXNW4RV4RV3X查看?usp=sharing

SimpleWorking04.xslhttps://drive.google.com/file/d/1OsOflQzGErvVFVsrmriqa0gbODS2查看?usp=sharing

如果您比较上述两个文件,则只是在 SimpleNotWorking04.xsl 中添加了一个空行,导致出现此错误.

注意不定位"后面的数字(例如不定位 10980:)将根据 XSL 内容而变化.

<块引用>

com.sun.org.apache.bcel.internal.generic.ClassGenException:不针对 10980:nop[0](1),但为空错误:不针对 10980:nop[0](1),但为空在 com.sun.org.apache.bcel.internal.generic.BranchInstruction.updateTarget(BranchInstruction.java:217)在 com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator.outline(MethodGenerator.java:1738)在 com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator.outlineChunks(MethodGenerator.java:1169)在 com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator.getGeneratedMethods(MethodGenerator.java:1899)在 com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator.addMethod(ClassGenerator.java:137)在 com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileNamedTemplate(Mode.java:557)在 com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileTemplates(Mode.java:566)在 com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileApplyTemplates(Mode.java:825)在 com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.compileModes(Stylesheet.java:622)在 com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:735)在 com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:478)在 com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:553)在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:947)在 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:761)在 simpletest.SimpleTest.main(SimpleTest.java:24) 错误:无法编译样式表"致命错误:不针对 10980:nop[0](1),但为空':不针对 10980:nop[0](1),但为空

代码很简单,如下.

import javax.xml.transform.Transformer;导入 javax.xml.transform.TransformerFactory;导入 javax.xml.transform.stream.StreamSource;导入 javax.xml.transform.TransformerConfigurationException;导入 java.io.File;公共类 SimpleTest {/*** @param args 命令行参数*/公共静态无效主(字符串 [] args){尝试{StreamSource 样式表 = new StreamSource(new File("SimpleNotWorking04.xsl"));TransformerFactory tFactory =TransformerFactory.newInstance();Transformer Transformer = tFactory.newTransformer(stylesheet);}抓住(变压器配置异常tce){System.out.println("错误:"+tce.getMessage());}捕获(异常 e){System.out.println("错误:"+e.getMessage());}捕获(可扔的 t){System.out.println("错误:"+t.getMessage());}System.out.println("转换完成!!");}}

解决方案

这是 Java 8 251 版本中的一个错误.在向 Oracle 报告后,该问题已修复并随 Java 8 271 October 2020 版本一起发布.

When trying to transform the stylesheet I get the following error from Java 1.8.0_251. Yet the same stylesheet transform without any issues with Java 1.8.0_241. I get the error when the line tFactory.newTransformer(stylesheet); is executed.

Also using xalan 2.7.2 instead of the Java 1.8.0._251 works as well but that version os xalan is really old.

Has anyone come across something like this? If so how to solve it?

SimpleNotWorking04.xsl https://drive.google.com/file/d/1pUiMvVtVBmBvCwfPXNW__pXVCiS4c3RV/view?usp=sharing

SimpleWorking04.xsl https://drive.google.com/file/d/1OsOflQzGErvVFVsrmriqa0gbODS2OWi5/view?usp=sharing

If you diff the two above files it's just one blank line added to the SimpleNotWorking04.xsl that gives this error.

NOTE the number after "Not targeting" (e.g. Not targeting 10980:) will change depending on the XSL content.

com.sun.org.apache.bcel.internal.generic.ClassGenException: Not   
targeting 10980: nop[0](1), but null ERROR:Not targeting 10980:   
nop[0](1), but null

 at    com.sun.org.apache.bcel.internal.generic.BranchInstruction.updateTarget(BranchInstruction.java:217)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator.outline(MethodGenerator.java:1738)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator.outlineChunks(MethodGenerator.java:1169)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator.getGeneratedMethods(MethodGenerator.java:1899)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator.addMethod(ClassGenerator.java:137)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileNamedTemplate(Mode.java:557)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileTemplates(Mode.java:566)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.Mode.compileApplyTemplates(Mode.java:825)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.compileModes(Stylesheet.java:622)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.translate(Stylesheet.java:735)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:478)
 at    com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:553)
 at    com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:947)
 at    com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:761)
 at simpletest.SimpleTest.main(SimpleTest.java:24) ERROR:  'Could not      compile stylesheet' FATAL ERROR:  'Not targeting 10980:
nop[0](1), but     null'
           :Not targeting 10980: nop[0](1), but null

The code is simple and is as below.

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.TransformerConfigurationException;
import java.io.File;

public class SimpleTest {

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
      try{
         StreamSource stylesheet = new StreamSource(new File("SimpleNotWorking04.xsl"));
         TransformerFactory tFactory =TransformerFactory.newInstance();  
         Transformer transformer = tFactory.newTransformer(stylesheet);
      }
      catch(TransformerConfigurationException tce) {
          System.out.println("ERROR:"+tce.getMessage());
      }
      catch(Exception e){
         System.out.println("ERROR:"+e.getMessage());
      }
      catch(Throwable t){
         System.out.println("ERROR:"+t.getMessage());
      }
      System.out.println("Done transformation!!");
   }

}

解决方案

This is a bug in Java 8 251 version. After reporting it to Oracle it was fix and released with Java 8 271 October 2020 release.

这篇关于使用 Java 1.8.0_251 转换 XSL 时发生致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆