Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4376145

First native method call crashes jvm & dll after a JFrame loads a dll.

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • 1.2.2, 1.3.0
    • hotspot
    • x86
    • windows_nt

      Customer Problem Description;
      -------------------------------
      Jdk1.2.2/ 1.3 seems to have a nasty problem w/ certain dlls I am loading
      from Java. In one case, I have a class which posts a swing JFrame w/ a
      JButton on it. Clicking the button loads a dll. My java wrapper
      implements Runnable so I can run the dll in it's own Thread. When the
      wrappers run method is called the dll trys to post a modal dialog over
      the top of the JFrame. This results in a msvc assertion failure in
      wincore.cpp, line 368 and causes the dll and the jvm to abruptly
      terminate without any exceptions or debugging information other than a
      dr watson log. To the best of our knowledge the problem occurs when a
      Microsoft ActiveX control is added and specifically when it trys to
      display that ActiveX control in the dialog box.

      Application exception occurred:
              App: java.exe (pid=136)
              When: 9/8/2000 @ 10:34:56.347
              Exception number: 80000003 (hardcoded breakpoint)

      Oddly enough when I run a java class w/ no gui component this dll loads fine and
      successfully posts the modal dialog and the functionality works fine. Also, I
      want to note, this code worked fine when using jdk1.1.7B!

       Attached are the files that you will need and the instructions follow:
           
           
           Environment:
           jdk1.2.2-001 ( Problem is also seen with jdk1.2.2-006, jdk1.3.0-C)
           Windows NT 4 Service Pack 4
           
           
           Attached is a dll built with MFC(5.0) as a zip. Also attached is a jar
           file and here are instructions for that code:
           
           These classes were compiled using jdk 1.2.2 from sun.
           1) create a directory c:\classes
           2) save the fleet.jar file in the c:\classes directory
           3) cd c:\classes
           4) jar xf fleet.jar
           5) set CLASSPATH=c:\classes;%CLASSPATH%
           6) java JFrame1
           
           The dll must be in c:\fleetdll
           These are stripped down versions of our actual applications. The dll
           is just a dialog box with the ActiveX control. The activeX is shipped
           with windows. Please run the java code and then click on the button
           to load the dll.

          Attached is also a Dr Watson log
      ---

      Name: krC82822 Date: 12/17/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-001, native threads, symcjit)

      I have a class which posts a swing JFrame w/ a JButton on it. Clicking
      the button loads a msvc dll. My java wrapper implements Runnable so I
      can run the dll in its own Thread. When the wrappers run method is
      called the dll is suppose to post its own window over the top of the
      JFrame. This results in a msvc assertion failure in wincore.cpp, line
      368 and causes the dll and the jvm abruptly terminate without any
      exceptions or debugging information.

      Environment: jdk 1.2.2-001 on Windows NT 4 with Service Pack 4
      Code:

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      /**
       * A basic JFC 1.1 based application.
       */
      public class TestDLL extends javax.swing.JFrame
      {
       public TestDLL()
       {
        //{{INIT_CONTROLS
        setTitle("JFC Application");
        getContentPane().setLayout(new BorderLayout(0,0));
        setSize(488,309);
        setVisible(false);
        JPanel1.setLayout(null);
        JPanel1.add(dllButton);
        dllButton.setBounds(180,75,108,48);
        getContentPane().add(BorderLayout.CENTER,JPanel1);
        dllButton.setText("ScanDLL");
        dllButton.setActionCommand("ScanDLL");
        //}}

        //{{REGISTER_LISTENERS
        SymWindow aSymWindow = new SymWindow();
        this.addWindowListener(aSymWindow);
        SymAction lSymAction = new SymAction();
        dllButton.addActionListener(lSymAction);
        //}}
       }

          /**
           * Creates a new instance of JFrame1 with the given title.
           * @param sTitle the title for the new frame.
           * @see #JFrame1()
           */
       public TestDLL(String sTitle)
       {
        this();
        setTitle(sTitle);
       }

       /**
        * The entry point for this application.
        * Sets the Look and Feel to the System Look and Feel.
        * Creates a new JFrame1 and makes it visible.
        */
       static public void main(String args[])
       {
        try {
                  //Create a new instance of our application's frame, and make
      it visible.
         (new TestDLL()).setVisible(true);
        }
        catch (Throwable t) {
         t.printStackTrace();
         System.exit(1);
        }
       }

       //{{DECLARE_CONTROLS
       javax.swing.JPanel JPanel1 = new javax.swing.JPanel();
       javax.swing.JButton dllButton = new javax.swing.JButton();
       //}}


       void exitApplication()
       {
        try {
            Toolkit.getDefaultToolkit().beep();
            int reply = JOptionPane.showConfirmDialog(this,
                                                      "Do you really want to
      exit?",
                                                      "JFC Application - Exit"
      ,

      JOptionPane.YES_NO_OPTION,

      JOptionPane.QUESTION_MESSAGE);
         // If the confirmation was affirmative, handle exiting.
         if (reply == JOptionPane.YES_OPTION)
         {
             this.setVisible(false); // hide the Frame
             this.dispose(); // free the system resources
             System.exit(0); // close the application
         }
        } catch (Exception e) {
        }
       }

       class SymWindow extends java.awt.event.WindowAdapter
       {
        public void windowClosing(java.awt.event.WindowEvent event)
        {
         Object object = event.getSource();
         if (object == TestDLL.this)
          JFrame1_windowClosing(event);
        }
       }

       void JFrame1_windowClosing(java.awt.event.WindowEvent event)
       {
        JFrame1_windowClosing_Interaction1(event);
       }

       void JFrame1_windowClosing_Interaction1(java.awt.event.WindowEvent
      event) {
        try {
         this.exitApplication();
        } catch (Exception e) {
        }
       }

       class SymAction implements java.awt.event.ActionListener
       {
        public void actionPerformed(java.awt.event.ActionEvent event)
        {
         Object object = event.getSource();
         if (object == dllButton)
          scanDLLItem_actionPerformed(event);
        }
       }

       void scanDLLItem_actionPerformed(java.awt.event.ActionEvent event)
       {
        System.out.println("Performing scandll button action");
              /* Start the ScanDLL as a separate Thread which both loads the
               * ScanDLL and calls the CallMyDialog() native method to post
               * the GUI */
              ScanDLL scanDLL = new ScanDLL();
              Thread scanDLLThread = new Thread(scanDLL);
              scanDLLThread.start();
              //Ensure the scanDll is up prior to proceeding
              while ( !scanDLL.isOKToScan() ) {
                  try {
                      System.out.println("Still Waiting");
                      Thread.currentThread().yield();
                      Thread.currentThread().sleep(1000);
                  } catch(Exception e) {
                      e.printStackTrace();
                  }
              }
              if ( scanDLL.isOKToScan() ) {
                  scanDLL.displayMessage("It is working!");
              }
          }
      }


      // Java wrapper which loads and calls dll method to post gui
      //public class ScanDLL implements Runnable {
      class ScanDLL implements Runnable {
          private static boolean okToExit = false;
          private static boolean dllLoaded = false;

       // Load dll which posts window on top of java gui
          static {
              System.load("c:\\dll\\ScanCss.dll");
          }

          public ScanDLL() {
          }

          public void run() {
              CallMyDialog(); // Call to native method which post gui
              setOkToExit(true);
          }

          public native void displayMessage(String msg);
          public native void errorMessage(int priority, String msg);
          public native void CallMyDialog();
          public native boolean isOKToScan();

          public static void setOkToExit(boolean flag) {
              okToExit = flag;
          }

          public static boolean isOkToExit() {
              return okToExit;
          }
      }
      (Review ID: 109175)
      ======================================================================

            jmcilreesunw James Mcilree (Inactive)
            cprasadsunw Ck Prasad (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: