JSLEE Discussions
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
NoClassDefFoundError for enum type (RhinoSDK-2.1_02 and JDK 1.6)
Forum Index » Rhino SLEE Discussions
Author Message
emil


Joined: 29/11/2009 18:19:16
Messages: 23
Offline

Hi,

I have an SBB (AuthorisationSBB) that is using an enum (in a switch statement) in one of the event handlers. The enum class exists in one of the jars that are part of the library jar which is used by the SBB. The SBB is using other (non enum) classes from the same jar without problems.

When the code runs I get NoClassDefFoundError on the line which has the switch statement.

Here is problem SBB:



ReasonType is just a standard enum:



Why do I get the NoClassDefFoundError?

The actual error is:



Thank you
Emil
emil


Joined: 29/11/2009 18:19:16
Messages: 23
Offline

Hi again,

the same problem exists when the enum is part of the SBB jar. For example, I created an enum (AuthorisationPhase) which is bundled in the SBB jar. The SBB now has a CMP filed which stores an AuthorisationPhase value:



In one of the event handlers I have a switch statement:



When the event handler runs I get NoClassDefFoundError on the `switch` line (switch (getAuthorisationPhase()) { ...).

So, can I use Java enums? If so, can you give me an example.

Thank you
Emil
oliver


Joined: 29/10/2008 09:36:04
Messages: 680
Location: Cambridge, UK
Offline


# Caused by: java.lang.ClassNotFoundException: au.com.prolancer.hsp.amc.service.authorisation.AuthorisationSbb$1


It is not the enum class itself that you are missing - it is an anonymous compiler-synthesized class ("AuthorisationSbb$1"). This will be a helper class generated by the compiler to support the enum switch/case statement. You probably want to include everything matching "AuthorisationSbb*.class" when building your SBB Jar.
[Email]
emil


Joined: 29/11/2009 18:19:16
Messages: 23
Offline

Thank you Oliver.

Yes, that is exactly what I was thinking initailly. But, I must be getting confused here, the javac compiler does not generate this class. I have 3 source files:

AuthorisationSbb.java
AuthorisationSbbAci.java
AuthorisationPhase.java <- this one is the enum

When I compile, I get

AuthorisationSbb.class
AuthorisationSbbAci.class
AuthorisationPhase.class

I bundle the above 3 class file + sbb-xml.jar file in an SBB jar. Go figure. It is driving me mad.

To add to my confusion, if I use an "if" statement instead of the "switch", it all works. For example, this works:



But this does not:



Need more coffee :( maybe.
Emil
oliver


Joined: 29/10/2008 09:36:04
Messages: 680
Location: Cambridge, UK
Offline

Well - it works as expected for me. I can only suggest you doublecheck what you're doing.



oliver@deluge:~$ javac TestEnumSwitch.java
oliver@deluge:~$ ls -l TestEnumSwitch*.class
-rw-r--r-- 1 oliver ocstaff 642 2010-01-19 16:39 TestEnumSwitch$1.class
-rw-r--r-- 1 oliver ocstaff 789 2010-01-19 16:39 TestEnumSwitch.class
-rw-r--r-- 1 oliver ocstaff 924 2010-01-19 16:39 TestEnumSwitch$TestEnum.class
oliver@deluge:~$ javac -version
javac 1.6.0_15
oliver@deluge:~$ java -classpath . TestEnumSwitch
one!
[Email]
emil


Joined: 29/11/2009 18:19:16
Messages: 23
Offline

Hi Oliver,

thank you for your help. Yes you are correct, if you use javac you get the extra class file. I was picking up the class files from the Eclipse project classes directory. For some reason Eclipse does not create the extra class file. Switching to and build scrips now.

Thank you again.

Emil
pgraham


Joined: 03/12/2010 10:16:21
Messages: 1
Offline

I've recently run into this problem and have a solution that is best demonstrated with an example:

First a little setup:

enum MyEnum { ... }

class MyEnumContainingClass {
MyEnum enumVal;
}

Not what doesn't work:

class SwitchOnEnum {

public static void main(String[] args) {
MyEnumContainingClass gotAnEnum = new MyEnumContainingClass();
gotAnEnum.enumVal = ...

switch(gotAnEnum.enumVal) {
// NoClassDef exception
}
}
}

But the following will work.

class SwitchOnEnum {
public static void main(String[] args) {
MyEnumContainingClass gotAnEnum = new MyEnumContainingClass();
gotAnEnum.enumVal = ...

MyEnum enumVal = gotAnEnum.enumVal;
switch(enumVal) {
// NoClassDef exception
}
}
}
emil


Joined: 29/11/2009 18:19:16
Messages: 23
Offline

Hi pgraham,

you can still use an enum in a separate class. All you have to do is, as suggested above, to bundle the the anonymous compiler-synthesized classes for the class that is using the enum. In your case SwitchOnEnum$1.class. You get similar compiler-synthesized classes if the enum is an inner class as well.

Emil
 
Forum Index » Rhino SLEE Discussions
Go to:   
Powered by JForum 2.1.8 © JForum Team