[java] Adding Classes to Package java.lang (Solved: legal by language spec, illegal by EULA)

Recommended Posts

Heyas! I can't find it in the spec, and eclipse seemingly lets me do it: Is it legal to declare a new class in java.lang or one of its subpackages? Specifically, I want to add a Class java.lang.NoClassDefFoundError to some of my binaries, as they run on a CLDC version that does not provide this error. Why, you ask? Because using the class keyword as in MyClass.class will cause javac to generate code that uses Class.forName and will catch the ClassNotFoundException and throw a NoClassDefFoundError instead. Basically, this creates a dependency on J2SE in the byte code, preventing coders from using the class keyword in CLDC-1.0 J2ME code. This is annoying, because it'd be really really useful for our automated build configuration system. [Edited by - Thygrrr on September 29, 2006 5:44:12 AM]

Share on other sites
You should probably take this question to: http://forum.java.sun.com/index.jspa

Lizard

Share on other sites
Quote:
 Original post by LizardCPPYou should probably take this question to...

Possibly, but I actually trust the Gamedev.net community more. I've seen horrendous bovine manure being posted on the Sun forums in the past.

Share on other sites
AFAIK it's illegal, I thinks that's in the EULA. And I'm pretty sure you'll get a "Cannot create class in system package" error when you try to install your app on the phone.

shmoove

Share on other sites
java.lang ist not system.* :)

The problem is, even if this works on all the CLDC-1.0 phones we have here, there's no certainty it'll work on all of them.

I'll try it, anyway.

Alternatively, I will have to work with Strings, which keeps a small smelly margin of error at compile time; just the kind of error I wanted to eradicate by making our build system completely preprocessor-free and suitable for refactoring.

EDIT:
Quote:
 D. Java Technology Restrictions. You may not create, modify, or change the behavior of, or authorize your licensees to create, modify, or change the behavior of, classes, interfaces, or subpackages that are in any way identified as "java", "javax", "sun" or similar convention as specified by Sun in any naming convention designation.

Okay, here it is. Well then, I'll just take the original java.lang.NoClassDefFoundError class from CLDC-1.1 and include it in my JAR. Thanks for the heads up, while the Error is probably a totally generic class, I'll take it in binary form directly from Sun, then. No creation, no modification, no changing. (still a bit edgy, though)

EDIT 2:
Hey, actually, that would make J2MEPolish's stub library illegal, as it contains class stubs in these packages. Same goes for the mpowerplayer SDK.

Hmm.

EDIT 3:
mvoss@jakarta ~\$ javap -c NoClassDefFoundErrorCompiled from "NoClassDefFoundError.java"public class java.lang.NoClassDefFoundError extends java.lang.Error{public java.lang.NoClassDefFoundError();  Code:   0:   aload_0   1:   invokespecial   #1; //Method java/lang/Error."<init>":()V   4:   returnpublic java.lang.NoClassDefFoundError(java.lang.String);  Code:   0:   aload_0   1:   aload_1   2:   invokespecial   #2; //Method java/lang/Error."<init>":(Ljava/lang/String;)V   5:   return}

Yup, it's a trivial class. Now to find out whether the Java Technology restrictions apply to application developers like us.

[Edited by - Thygrrr on September 29, 2006 6:16:24 AM]

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627682
• Total Posts
2978615

• 13
• 12
• 10
• 12
• 22