在精简JRE过程中,将rt.jar中类通过FileInputStream,FileOutputStream进行拷贝操作出错:

java.lang.ClassFormatError: Extra bytes at the end of class file

源代码:

  1. byte buf[] = new byte[256];
  2. while(fin.read(buf) != -1)
  3. {
  4. fout.write(buf);
  5. ir.read();
  6. }
  7. fout.flush();

修改后:

  1. byte buf[] = new byte[256];
  2. int len = 256;
  3. while((len = fin.read(buf)) != -1)
  4. {
  5. fout.write(buf,0,len);
  6. ir.read();
  7. }
  8. fout.flush();

相关资料:

java.lang.ClassFormatError thrown when applet runs

Symptoms

When running an applet in a browser using the Sun JVM, a ClassFormatError is thrown by theClassLoader. The same applet runs under the Microsoft  VM.

Cause

This error is caused by bytecodes generated from old JDK 1.0.2/1.1 compilers, or from a third-party obfuscator. In the past, many of these compilers and obfuscators generated bytecode that does not conform to the Java VM Specification. Because the verifiers in recent J2SE releases are much stricter about bad class format, the ClassFormatError is thrown by the VM when these bad class files are loaded.

Some typical problems in some older class files are the following (note that this list is not exhaustive):

  • There are extra bytes at the end of the class file.
  • The class file contains method or field names that do not begin with a letter.
  • The class attempts to access private members of another class.
  • The class file has other format errors, including illegal constant pool indices and illegal UTF-8 strings.
  • The class file produced by an early (third-party) bytecode obfuscator violates proper class-file format.

Resolution

To allow some of the applets with bad class files to run in the Java 2 platform, Java Plug-in contains a bytecode transformer to transform some of the bad class files to good ones. Currently, only bad class files with the following problems may be transformed:

  • Local variable name with a bad constant pool index
  • Extra bytes at the end of the class file
  • Code segment of the wrong length
  • Illegal field/method name
  • Illegal field/method modifiers
  • Invalid start_pc/length in local var table

Unfortunately, the bytecode transformer cannot transform the following problems, which will still result in a ClassFormatError:

  • Illegal use of nonvirtual function call
  • Arguments can't fit into locals
  • Unsorted lookup switch
  • Truncated class file

You can resolve these problems by simply recompiling your Java classes with the javac compiler from the Java 2 SDK. If you choose to use a third-party obfuscator, be sure to use one that produces class files that respect proper class-file format.

相关资料: http://download.oracle.com/javase/1.4.2/docs/guide/deployment/deployment-guide/upgrade-guide/article-01.html

java.lang.ClassFormatError: Extra bytes at the end of class file的更多相关文章

  1. 阿里巴巴 fastjson-1.2.12.jar json解析异常java.lang.ClassFormatError: Invalid method Code length 66865 in class file com/alibaba/fastjson/serializer/ASMSerializer_6_UserKdlb

    承接上篇:fastjson反序列化LocalDateTime失败的问题java.time.format.DateTimeParseException: Text '2019-05-24 13:52:1 ...

  2. java.lang.ClassFormatError: Illegal UTF8 string in constant pool in class file Server/Request

    Linux服务器上,将本地编译好的文件上传后,Tomcat启动时报错: Exception in thread "Thread-2" java.lang.ClassFormatEr ...

  3. IZ65534: 'JAVA.LANG.CLASSFORMATERROR' ERROR FOR A VALID IDENTIFIER

    PAR status Closed as program error. Error description Error Message: The java class could not be loa ...

  4. java.lang.ClassFormatError

    Error occurred during initialization of VMjava.lang.ClassFormatError: Unknown constant tag 26 in cla ...

  5. java.lang.ClassFormatError Duplicate field name&signature in class file XXXXXX【转】

    本文转载自:https://blog.csdn.net/ylchou/article/details/7739742 2012-7-5 15:06:25org.apache.catalina.core ...

  6. spring运行时没有问题,在单元测试时,出现java.lang.ClassFormatError错误

    Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstrac ...

  7. java.lang.ClassFormatError: Unknown constant tag 0 in class file

    在通过文件上传之后,运行java程序,突然发现这么一个错误:java.lang.ClassFormatError: Unknown constant tag 0 in class file,通过网上查 ...

  8. java.lang.ClassFormatError: Trjava.lang.ClassFormatError: Truncated class fileuncated class file

    周末过来加班,上传编译好的文件后,部署到服务器没事.但是服务器日志满了,把日志清除后,把服务启动,发现报这个错误,大致网上看了一下,这个错误是编译的文件损坏了.然后大致看了一下文件,还真是.由于日志满 ...

  9. java.lang.ClassFormatError: Truncated class file

    之前跑的很好的程序,因为我本地IDE出了问题的原因,倒是编译的错误的class文件,结果点击的时候报这样的错误,后来重新clean了工程,重新打包解压启动,问题依旧. 解决办法: 把tomcat的wo ...

随机推荐

  1. sql基础语法复习

    约定:数据库名:test:表名:tb1,tb2,tb3…: 对象:数据库:database 表:table 列:column 索引:index 视图:view 存储过程:procedure 一.数据结 ...

  2. Web框架Django

    Django是一个开放源代码的Web应用框架,由Python写成. 1. Ubuntu Django安装: pip install django 2. django-admin.py创建一个项目 dj ...

  3. Postfix常用命令和邮件队列管理(queue)

    本文主要介绍一下postfix的常用命令及邮件队列的管理: Postfix有以下四种邮件队列,均由管理队列的进程统一进行管理: maildrop:本地邮件放置在maildrop中,同时也被拷贝到inc ...

  4. Ubuntu 12.04.1 OK335xS busybox-1.24.1 文件系统编译错误及解决方案

    Ubuntu OK335xS busybox- 文件系统编译错误及解决方案 一.参考文档: 编译busybox的一些错误: http://blog.csdn.net/hshl1214/article/ ...

  5. JVM原理二----JAVA虚拟机体系结构

    组成: 指令集,寄存器,栈,无用单元收集(GC),方法区域.JAVA核心 1,指令集:这个不太清楚 2,寄存器:和处理器中的寄存器类似 pc:Java程序计数器. optop:指向*作数栈顶端的指针. ...

  6. 获取css最终样式

    function getStyle(obj, attr) { if (obj.currentStyle) { return obj.currentStyle[attr]; } else { retur ...

  7. BZOJ1001 BeiJing2006 狼抓兔子 【网络流-最小割】*

    BZOJ1001 BeiJing2006 狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较 ...

  8. 【angularJS】启动(bootstrap)机制

    Angular的启动分为手动和自动两种. 自动启动 定义模块的例子中,采用的就是自动的方式:通过内置的指令ngApp 来指定启动时加载的模块.<html ng-app="myApp&q ...

  9. Google、IBM和Lyft开源其大型微服务系统管理工具Istio

    Istio 的优势 集群规模可视性:在故障状况出现时,运营人员需要利用多种工具以始终关注集群运行状况并分析微服务状态图表.Istio 项目能够监控与应用程序及网络活动相关的数据,利用 Promethe ...

  10. 福勒(Martin Fowler)

    福勒(Martin Fowler),在面向对象分析设计.UML.模式.软件开发方法学.XP.重构等方面,都是世界顶级的专家,现为Thought Works公司的首席科学家.Thought Works是 ...