MOTODEV Studio & SDK for Java ME
Log In  ·  Help
Jump to Page:   1
  Reply   Reply  

newInstance() not allowed, even with 'maximum' trust settings
Options    Options  
arnauvp
Visitor
Posts: 4
Registered: 10-28-2009


arnauvp

Message 1 of 4

Viewed 97 times


Hi again,

 

I have a similar problem from that explained in this other post. In my code I use newInstance() to create instances of a certain class, very used. I can call it a number of times (around 25) but then it fails with the trace:

 

java.lang.NoClassDefFoundError: sun/reflect/ConstructorAccessorImpl
    at sun.misc.Unsafe.defineClass(Native Method)
    at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:45)
    at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:381)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:377)
    at sun.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:76)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:30)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)

 

If this is a 'security' mechanism, as explained on the other Thread, I don't understand. The MIDP Javadocs define that newInstance() can only throw:

- IllegalAccessException - if the class or initializer is not accessible.

- InstantiationException - if an application tries to instantiate an abstract class or an interface, or if the instantiation fails for some other reason.

 

Also, my midlet is signed (and the emulator parameter 'Security domain' is set to 'maximum' in Pulsar). IMHO, this is a bug.

Can anyone from Motorola comment on this?

 

Thanks,

Arnau

 

Kudos!
11-03-2009 03:03 AM
 
  Reply   Reply  

Re: newInstance() not allowed, even with 'maximum' trust settings
Options    Options  
gator
Technical Expert
Posts: 137
Registered: 03-06-2009


gator

Message 2 of 4

Viewed 89 times


Hi,

 

Sign the MIDlet or not doesn't matter. It is implemented in this way by SUN (with some security concern, as I know).

 

In our LinuxOS phones, the JVM is SUN CLDC HotSpot. And it is also SUN who made the MIDP specification.

 

The classForName() and newInstance() use the internal classLoader of JVM and create classes with reflection mechanism.

 

But in real implementation, if the class created by newInstance() is a preload class, normally it works correctly; but for a developer made class, it doesn't (in some early version, it throws out the exception in the first time).

 

Regards

 

Yu Feng

 

 

 

 

Kudos!
11-04-2009 12:01 AM
 
  Reply   Reply  

Re: newInstance() not allowed, even with 'maximum' trust settings
Options    Options  
arnauvp
Visitor
Posts: 4
Registered: 10-28-2009


arnauvp

Message 3 of 4

Viewed 87 times


Hi gator,

 

thanks for your answer, but my midlet works perfectly fine on the Sun WTK, Sun JavaME 3.0, SonyEricsson and Nokia SDKs. And of course on phones. Only now I am working on Linux and I have a reduced choice for SDKs, Motorola being one of the few. Also, if there really was a limitation I think it would be explained on the Javadocs. And, in any case, it is wrong to throw ClassNotFound because the MIDP spec declares only those two kind of exceptions for this method, and 'InstantiationException' seems perfectly valid for this case.

 

Arnau

Kudos!
11-04-2009 12:43 AM
 
  Reply   Reply  

Re: newInstance() not allowed, even with 'maximum' trust settings
Options    Options  
gator
Technical Expert
Posts: 137
Registered: 03-06-2009


gator

Message 4 of 4

Viewed 59 times


Hi,

 

We're sorry about that. I also think it is a defect. The implementation is conflict with the specification.

 

Regards

 

Yu Feng

Kudos!
11-08-2009 07:01 PM
 
Jump to Page:   1