Solved

Class loader Problem

Posted on 2003-11-13
12
397 Views
Last Modified: 2013-11-23
I have an ejb client application that works fine when deployed manually. I then decided to decided to deploy with Java Web Start, the deployment goes fine but some of the app. functions don't work and return an error on the console. Here is a copy of the error message.

Java Web Start Console, started Thu Nov 13 10:38:39 EST 2003

Java 2 Runtime Environment: Version 1.4.0_03 by Sun Microsystems Inc.

Logging to file: C:\Test-me\Log.txt

java.lang.ClassFormatError: cc/admin/email/client/AdministratorUI$18 (Illegal Variable name " val$jtf")

      at java.lang.ClassLoader.defineClass0(Native Method)

      at java.lang.ClassLoader.defineClass(Unknown Source)

      at java.security.SecureClassLoader.defineClass(Unknown Source)

      at com.sun.jnlp.JNLPClassLoader.defineClass(Unknown Source)

      at com.sun.jnlp.JNLPClassLoader.access$1(Unknown Source)

      at com.sun.jnlp.JNLPClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(Native Method)

      at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClassInternal(Unknown Source)

      at cc.admin.email.client.AdministratorUI.createTermAndYearDialog(AdministratorUI.java:440)

      at cc.admin.email.client.AdministratorUI.jMenuItemSCTAY_actionPerformed(AdministratorUI.java:398)

      at cc.admin.email.client.AdministratorUI.access$6000471(AdministratorUI.java:77)

      at cc.admin.email.client.AdministratorUI$6.actionPerformed(AdministratorUI.java:212)

      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

      at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown Source)

      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)

      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)

      at javax.swing.AbstractButton.doClick(Unknown Source)

      at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)

      at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)

      at java.awt.Component.processMouseEvent(Unknown Source)

      at java.awt.Component.processEvent(Unknown Source)

      at java.awt.Container.processEvent(Unknown Source)

      at java.awt.Component.dispatchEventImpl(Unknown Source)

      at java.awt.Container.dispatchEventImpl(Unknown Source)

      at java.awt.Component.dispatchEvent(Unknown Source)

      at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)

      at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)

      at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)

      at java.awt.Container.dispatchEventImpl(Unknown Source)

      at java.awt.Window.dispatchEventImpl(Unknown Source)

      at java.awt.Component.dispatchEvent(Unknown Source)

      at java.awt.EventQueue.dispatchEvent(Unknown Source)

      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

      at java.awt.EventDispatchThread.run(Unknown Source).



The portion of my code responsible for this is:

 final JTextField jtf = new JTextField(termAndYear[1]);
    jtf.addKeyListener(new JTextFieldFormat(jtf,4));    
    jtf.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusGained(FocusEvent e) {
          jtf.setCaretPosition(0);
          jtf.selectAll();
        }
      });


Apart from that action, the application works just fine. The interesting thing is, this does not happen if I run the application locally using the required jar files. It only happens when deployed with Java Web Start.

I'll appreciate any help. Thanks
0
Comment
Question by:kunlenzo247
  • 5
  • 3
  • 2
12 Comments
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9740695
What is a JTextFieldFormat?  It doesn't appear in the 1.4.2 API.  Is this a custom-built class or am I missing something?

Right now, it smells an awful lot like this issue is the JDK/JRE version, unless a JTextFieldFormat is a custom-built class, and perhaps you're not uploading the right .jar file for it.
0
 
LVL 7

Accepted Solution

by:
Igor Bazarny earned 50 total points
ID: 9740867
It may be JVM bug. Try later JVM version or make your focus listener named class with explicit JTextField field. You can also rewrite your code this way:
jtf.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusGained(FocusEvent e) {
          ((JTextField)e.getSource()).setCaretPosition(0);
          ((JTextField)e.getSource()).selectAll();
        }
      });
Regards,
Igor Bazarny
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9740923
The fact that jtf is final means that it's properly visible to it's anonymous inner class.  I strongly suspect the problem is with this JTextFieldFormat object, which doesn't appear to have any definition I've ever heard of.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:kunlenzo247
ID: 9741687
Thanks buddy. JTextFieldFormat is a custom class but I think I have a lead on what the issue is. It has to do with the inner class loading and the final objects that I declared. When I comment those lines(jtf.setCaretPosition(0) and jtf.selectAll()) and redo the packaging, it doesn't come up with the errors. So I guess it's because of the inner class.
The problem is, I have a couple of inner classes referencing final objects in my app. What can I do please?
Thanks

Kunle
0
 
LVL 2

Assisted Solution

by:SuperKarateMonkey
SuperKarateMonkey earned 50 total points
ID: 9742128
Easy:  Just register the class as the appropriate listener, and implement the listener methods, instead of using anonymous inner classes, (the Adapters.)

For example, let's assume the name of your class is WhatEverClassThisIs, and replace this:

final JTextField jtf = new JTextField(termAndYear[1]);
    jtf.addKeyListener(new JTextFieldFormat(jtf,4));    
    jtf.addFocusListener(new java.awt.event.FocusAdapter() {
        public void focusGained(FocusEvent e) {
          jtf.setCaretPosition(0);
          jtf.selectAll();
        }
      });


with this:

WhatEverClassThisIs... ...implements FocusListener
{

private JTextField jtf;  // Gotta be a member variable, so it's visible in all methods.
...
    jtf = new JTextField(termAndYear[1]);  // Just assign the variable here, don't declare it.
    jtf.addKeyListener(new JTextFieldFormat(jtf,4));    
    jtf.addFocusListener( this );

// This is now a method of WhatEverClassThisIs
public void focusGained(FocusEvent e)
{
jtf.setCaretPosition(0);
jtf.selectAll();
}
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9742139
Oh ,and you'll also need to add one additional method to your class:

public void focusLost( FocusEvent e )
{
// Do nothing
}

Otherwise, you don't actually implement FocusListener
0
 

Author Comment

by:kunlenzo247
ID: 9742185
Here is an example of a method that sets a table model based on parameters passed.

private void updateUIComponents(final JTable table,
                                  final Object[][] records,
                                  final String[] header) {    
    Runnable doSetTableValues = new Runnable() {
      public void run() {
        table.setModel(createTableModel(records,header));
      }
    };
    SwingUtilities.invokeLater(doSetTableValues);
  }

And I have other instances that are simlilar. Does it mean that my only solution is to re-code all over especially considering the fact that it runs fine locally using the same runtime.

Thanks.
0
 
LVL 2

Expert Comment

by:SuperKarateMonkey
ID: 9742369
Well, if the problem is simply in the anonymous inner classes, then no, you needn't re-code.  Just eliminate them and implement the interfaces instead.

As for this runnable stuff, Runnable is an interface as well.  You can have another class implement it and then use that class instead, though in that case you might not be able to have your master class implement it itself, since you're deferring execution.

However, it's entirely possible that the errors are only coming from the adapters, not the Runnable().  Try eliminating the adapters first, then see if it'll work.  I'm not precisely sure why you can't use anonymous inner classes with Java Web Start:  It might have to do with the security manager treating web start stuff as applets, perhaps.

Also look into solving this threading problem with a Thread object, or a TimerTask.  I couldn't give any suggestions how without seeing the code, but that might work if the Runnable stuff is hosing you.
0
 

Author Comment

by:kunlenzo247
ID: 9743316
I think you are right about the security manager cos I read up on ClassLoader and defineClass() (like I pasted above) and realised that my anonymous inner classes are responsible for the result because the default class loader cannot  correlate my objects that I declared as final with the corresponding classes. I really don't fancy the idea of restructuring the codes all-over.
Maybe it's a bug that needs to be fixed in Java Web Start cos I also came across a simlilar thread in a JDC forum. i.e
          http://forum.java.sun.com/thread.jsp?forum=38&thread=372291
You could check it out too. It's exactly what I'm facing and no known solution yet. I'll appreciate any further contributions. Once again, thanks for your efforts.

Kunle.
0
 
LVL 7

Expert Comment

by:Igor Bazarny
ID: 9746986
The field it's complaining about is synthetic field in the anonymous class, inserted by the compiler. This field refers to the value of the final local variable. It is not the local variable itself. Apparently classloader doesn't like the field name created by the compiler.
There is no way to control field name compiler uses. If moving to another JVM is not an option (and we still don't know whether 1.4.2 has this problem), the only solution I see is change of code so that there will be no synthetic fields.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
session migration servlets 2 42
more than one jdk and one jre 1 50
oracle 11g 23 106
how to install java on RHEL image on EC2 4 39
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question