Bug 43792 - Illegal Opcode Detected
Summary: Illegal Opcode Detected
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.1.1   Edit
Hardware: PC Windows XP
: P2 blocker (vote)
Target Milestone: 1.2   Edit
Assignee: Erik Hilsdale CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-27 10:31 EDT by Umit VARDAR CLA
Modified: 2004-03-19 09:48 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Umit VARDAR CLA 2003-09-27 10:31:28 EDT
I'm using ajdt 1.1.4 with eclipse 2.1.2 on Win/XP + j2sdk1.4.2 + Turkish 
Locale.
When I try to build project files I'm, constantly, getting
"ClassGen exception: Illegal Opcode Detected" error. I tried to use 1.1.3 
version but noavail.
This error is also reprodicable with command line compiler. 
You can use the "Hello world" example from Laddad's books to reproduce the 
error.

PS. When I switch the locale of my machine to English everything is ok. 

PPS. Usually I encounter problems with locale if developer makes character 
case conversion (esp i, I) without specifying Locale.US but assuming that is 
the case. Because in turkish locale "I".toLowerCase() != "i" and 
also "i".toUpperCase() != "I"

below the error produced by command line compiler:

Illegal opcode detected.
Illegal opcode detected.
org.apache.bcel.generic.ClassGenException: Illegal opcode detected.
	at org.apache.bcel.generic.Instruction.readInstruction
(Instruction.java:189)
	at org.apache.bcel.generic.InstructionList.<init>
(InstructionList.java:193)
	at org.apache.bcel.generic.MethodGen.<init>(MethodGen.java:165)
	at org.aspectj.weaver.bcel.LazyMethodGen.<init>(LazyMethodGen.java:141)
	at org.aspectj.weaver.bcel.LazyClassGen.<init>(LazyClassGen.java:110)
	at org.aspectj.weaver.bcel.BcelObjectType.getLazyClassGen
(BcelObjectType.java:248)
	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:359)
	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:335)
	at org.aspectj.weaver.bcel.BcelWeaver.weave(BcelWeaver.java:261)
	at 
org.aspectj.ajdt.internal.core.builder.AjBuildManager.weaveAndGenerateClassFile
s(AjBuildManager.java:256)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.doBuild
(AjBuildManager.java:164)
	at org.aspectj.ajdt.internal.core.builder.AjBuildManager.batchBuild
(AjBuildManager.java:78)
	at org.aspectj.ajdt.ajc.AjdtCommand.doCommand(AjdtCommand.java:106)
	at org.aspectj.ajdt.ajc.AjdtCommand.runCommand(AjdtCommand.java:60)
	at org.aspectj.tools.ajc.Main.run(Main.java:217)
	at org.aspectj.tools.ajc.Main.runMain(Main.java:155)
	at org.aspectj.tools.ajc.Main.main(Main.java:72)


1 fail|abort, 1 warning
Comment 1 Mik Kersten CLA 2003-09-30 00:00:01 EDT
Moved to AspectJ project.
Comment 2 Erik Hilsdale CLA 2003-11-17 18:10:04 EST
Okay, this sure looks like a BCEL error.  Looking at 

    org.apache.bcel.generic.Instruction.className(short)

they definitely use toUpperCase(), which was very helpfully
suggested as a problem call in the Turkish locale.  

(as a side note, BCEL is using _reflection_ to instantiate
its bytecode operations!  What the hell happened to programmers'
brains?  Because reflection is available they should use it
instead of a dispatch table with EXTREMELY well-specified
entries?  It took _effort_ to be that lazy!  I wouldn't even
use eval to accomplish this task in Scheme!  Okay, rant over)

We may have to check in our own patched version of BCEL to
handle this problem.  I'm investigating whether the BCEL
folks know about this problem.  Leaving as P2; we should
definitely fix this before 1.2.

Thanks very much to Umit Vardar for the bug report.

-erik
Comment 3 Erik Hilsdale CLA 2003-11-19 16:39:09 EST
Submitted the bug to BCEL folks yesterday, and a test case (for BCEL) today:

import java.io.IOException;
import java.util.Locale;

import org.apache.bcel.generic.Instruction;
import org.apache.bcel.util.ByteSequence;

public class LocaleTest {
	public static void main(String[] args) throws IOException {
		printBipush();
		Locale.setDefault(new Locale("tr"));
		printBipush();  // this throws an exception!
	}
	
	static void printBipush() throws IOException {
		Instruction ix = Instruction.readInstruction(
			new ByteSequence(new byte[] { 
				(byte)16, // bipush 
				(byte) 3  // data for bipush
				}));
		System.err.println(ix);
	}
}

I'm going to give the BCEL folks a week to address the issue
before exploring whether we need to include a patched BCEL
version. 

I couldn't find a way to pass a locale specification to _our_
command-line compiler, so I don't have a test case for this
bug checked into our tree.  

As a side note, the workaround for this problem is to avoid
writing programs that use the bytecodes:

bipush, sipush, iload*, istore*, iinc, if*, put/getstatic,
put/getfield, invoke*, instanceof, multianewarray

so as long as you're not using integers, bytes, shorts, or 
conditionals, fields, or methods, this problem won't affect 
you at all. *grin*.
Comment 4 Erik Hilsdale CLA 2004-01-29 07:33:19 EST
Okay, this is now fixed, and we're now using a patched version of BCEL
for our project.  BCEL folks were no help, but I contributed
the fix I used as a patch to their bug system.  
Test case also checked in.
Comment 5 Adrian Colyer CLA 2004-03-19 09:48:09 EST
updating target flag to indicate inclusion in 1.2 release.