JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6514

java.lang.NullPointerException when using ScriptingCotainer from an Appletjava.lang.NullPointerException

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.7
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Win7 64 bit
      Netbeans 7.1
      jdk-7u3
    • Number of attachments :
      1

      Description

      Call Rubyscript results in NullPonterException when called from a JApplet:

      Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
      at org.jruby.util.OSEnvironment.addRubyKeyValuePair(OSEnvironment.java:101)
      at org.jruby.util.OSEnvironment.getAsMapOfRubyStrings(OSEnvironment.java:85)
      at org.jruby.util.OSEnvironment.getEnvironmentVariableMap(OSEnvironment.java:51)
      at org.jruby.RubyGlobal.defineGlobalEnvConstants(RubyGlobal.java:411)
      at org.jruby.RubyGlobal.createGlobals(RubyGlobal.java:363)
      at org.jruby.Ruby.init(Ruby.java:1094)
      at org.jruby.Ruby.newInstance(Ruby.java:184)
      at org.jruby.embed.internal.LocalContext.getThreadSafeRuntime(LocalContext.java:69)
      at org.jruby.embed.internal.ThreadSafeLocalContextProvider.getRuntime(ThreadSafeLocalContextProvider.java:61)
      at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.runParser(EmbedRubyRuntimeAdapterImpl.java:166)
      at org.jruby.embed.internal.EmbedRubyRuntimeAdapterImpl.parse(EmbedRubyRuntimeAdapterImpl.java:93)
      at org.jruby.embed.ScriptingContainer.parse(ScriptingContainer.java:1195)
      at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:1255)
      at javaappletnruby.NewJApplet.jButton1ActionPerformed(NewJApplet.java:102)
      at javaappletnruby.NewJApplet.access$200(NewJApplet.java:14)
      at javaappletnruby.NewJApplet$2.actionPerformed(NewJApplet.java:79)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.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.Component.dispatchEvent(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$000(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.awt.EventQueue$4.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(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)
      plugin2manager.parentwindowDispose

      Code:

      import org.jruby.embed.LocalContextScope;
      import org.jruby.embed.ScriptingContainer;

      /**
      *

      • @author z0032mnt
        */
        public class NewJApplet extends javax.swing.JApplet {
        private ScriptingContainer c;

      /**

      • Initializes the applet NewJApplet
        */
        @Override
        public void init() {
        /*
      • Set the Nimbus look and feel
        */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
      • If Nimbus (introduced in Java SE 6) is not available, stay with the
      • default look and feel. For details see
      • http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
        */
        try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
        Unknown macro: { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } }

        } catch (ClassNotFoundException ex)

        { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); }

        catch (IllegalAccessException ex)

        { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); }

        //</editor-fold>

      /*

      • Create and display the applet
        */
        try {
        java.awt.EventQueue.invokeAndWait(new Runnable() {

      public void run()

      { initComponents(); c = new ScriptingContainer(LocalContextScope.THREADSAFE); c.runScriptlet("puts 'wooopwoop'"); }

      });
      } catch (Exception ex)

      { ex.printStackTrace(); }

      }

      /**

      • This method is called from within the init() method to initialize the
      • form. WARNING: Do NOT modify this code. The content of this method is
      • always regenerated by the Form Editor.
        */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {

      jButton1 = new javax.swing.JButton();

      jButton1.setText("jButton1");
      jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt)

      { jButton1ActionPerformed(evt); }

      });

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addGap(139, 139, 139)
      .addComponent(jButton1)
      .addContainerGap(188, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addGap(71, 71, 71)
      .addComponent(jButton1)
      .addContainerGap(206, Short.MAX_VALUE))
      );
      }// </editor-fold>

      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)

      { c.runScriptlet("puts 'wooopwoop'"); }

      // Variables declaration - do not modify
      private javax.swing.JButton jButton1;
      // End of variables declaration
      }

        Activity

        Hide
        peter added a comment -

        sorry for the messed up title

        Show
        peter added a comment - sorry for the messed up title
        Hide
        peter added a comment - - edited

        no need for the code part, attached my nbproject for this.

        This is only a issue in an unsigned Applet, it works in an signed.

        Show
        peter added a comment - - edited no need for the code part, attached my nbproject for this. This is only a issue in an unsigned Applet, it works in an signed.
        Hide
        Charles Oliver Nutter added a comment -

        The problem is that it's using a "safe" lookup of user.dir, which results in it being null in an unsecure environment like an unsigned applet. Will fix.

        Show
        Charles Oliver Nutter added a comment - The problem is that it's using a "safe" lookup of user.dir, which results in it being null in an unsecure environment like an unsigned applet. Will fix.
        Hide
        Charles Oliver Nutter added a comment -
        commit 874e63020db592e8c5c8908ad53ccca94455e13b
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Wed Aug 1 20:39:54 2012 -0500
        
            Fix JRUBY-6514
            
            java.lang.NullPointerException when using ScriptingCotainer from an Applet
            
            Properties retrieved in a restricted environment may be null. We
            must handle that case and not blindly try to getBytes().
        
        :100644 100644 cfc2e04... 94cd24e... M	src/org/jruby/util/OSEnvironment.java
        
        Show
        Charles Oliver Nutter added a comment - commit 874e63020db592e8c5c8908ad53ccca94455e13b Author: Charles Oliver Nutter <headius@headius.com> Date: Wed Aug 1 20:39:54 2012 -0500 Fix JRUBY-6514 java.lang.NullPointerException when using ScriptingCotainer from an Applet Properties retrieved in a restricted environment may be null. We must handle that case and not blindly try to getBytes(). :100644 100644 cfc2e04... 94cd24e... M src/org/jruby/util/OSEnvironment.java

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            peter
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: