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

(未完,待修改) 

 

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

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

 

源代码:

byte buf[] = new byte[256];
while(fin.read(buf) != -1)
{
	fout.write(buf);
	ir.read();
}
fout.flush();

 

修改后:

byte buf[] = new byte[256];
int len = 256;
while((len = fin.read(buf)) != -1)
{
	fout.write(buf,0,len);
	ir.read();
}
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 the ClassLoader. 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值