Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resetting content type for multiple editor panes yields NPE #172

Open
GoogleCodeExporter opened this issue Sep 22, 2015 · 1 comment
Open

Comments

@GoogleCodeExporter
Copy link

Under v0.9.5 on Windows 7, the following code causes a NullPointerException:

public static void main(String[] pArgs) {
  DefaultSyntaxKit.initKit();

  final JEditorPane[] editorPanes = new JEditorPane[2];

  for (int i = 0; i < editorPanes.length; i++) {
    editorPanes[i] = new JEditorPane();
  }

  final JFrame frame = new JFrame(
    TrialPanel.class.getName() + " Test"
  );
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  frame.add(
    new JSplitPane(
      JSplitPane.VERTICAL_SPLIT,
      new JScrollPane(editorPanes[0]),
      new JScrollPane(editorPanes[1])
    )
  );
  frame.add(
    new JButton(
      new AbstractAction("Reset Content Type") {
        private String[] types = new String[] {
          "text/java", "text/javascript"
        };
        private int i;

        @Override public void actionPerformed(ActionEvent pEvt) {
          final String type = types[i++ % types.length];
          System.out.println("Type: " + type);
          for (JEditorPane editorPane : editorPanes) {
            editorPane.setContentType(type);
          }
        }
      }
    ),
    BorderLayout.SOUTH
  );

  frame.pack();
  frame.setVisible(true);
}
------
Press the button a few times and the following stacktrace is generated:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at jsyntaxpane.DefaultSyntaxKit.deinstall(DefaultSyntaxKit.java:345)
    at javax.swing.JEditorPane.setEditorKit(JEditorPane.java:1091)
    at javax.swing.JEditorPane.setContentType(JEditorPane.java:1019)
    at Test$1.actionPerformed(Test.java:49)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6289)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
    at java.awt.Component.processEvent(Component.java:6054)
    at java.awt.Container.processEvent(Container.java:2041)
    at java.awt.Component.dispatchEventImpl(Component.java:4652)
    at java.awt.Container.dispatchEventImpl(Container.java:2099)
    at java.awt.Component.dispatchEvent(Component.java:4482)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.java:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4482)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
    at java.awt.EventQueue.access$000(EventQueue.java:85)
    at java.awt.EventQueue$1.run(EventQueue.java:603)
    at java.awt.EventQueue$1.run(EventQueue.java:601)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:617)
    at java.awt.EventQueue$2.run(EventQueue.java:615)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Original issue reported on code.google.com by [email protected] on 15 Mar 2011 at 5:21

@GoogleCodeExporter
Copy link
Author

Don't clear DefaultSyntaxKit.editorComponent map.

Original comment by [email protected] on 2 Jul 2011 at 3:11

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant