bobbylight / RSyntaxTextArea

A syntax highlighting, code folding text editor for Java Swing applications.
BSD 3-Clause "New" or "Revised" License
1.12k stars 259 forks source link

Cannot invoke "javax.swing.text.JTextComponent.isEditable()" because "this.component" is null #489

Closed mps77 closed 1 year ago

mps77 commented 1 year ago

Constructor bug in squirellsql or jdk bug?

Steps to Reproduce run squirellsql with jdk 20,21

Expected behavior Works with jdk 19 :)

Actual behavior Constructor error

Screenshots image

Java version jdk 20-ea+31-2311 win32, openjdk 21-ea+9-678 win32

Version

Manifest-Version: 1.0 Bnd-LastModified: 1641768912829 Bundle-License: BSD-3-Clause Bundle-ManifestVersion: 2 Bundle-Name: rsyntaxtextarea Bundle-SymbolicName: rsyntaxtextarea Bundle-Version: 3.1.6 Created-By: 1.8.0_20 (Oracle Corporation) Implementation-Title: org.fife.ui Implementation-Version: 3.1.6

StackTrace

Exception (jdk 20-ea+31-2311 win32, openjdk 21-ea+9-678 win32) java.lang.NullPointerException: Cannot invoke "javax.swing.text.JTextComponent.isEditable()" because "this.component" is null at java.desktop/javax.swing.text.DefaultCaret.setBlinkRate(DefaultCaret.java:1053) at org.fife.ui.rtextarea.RTextAreaUI.createCaret(RTextAreaUI.java:172) at java.desktop/javax.swing.plaf.basic.BasicTextUI.installDefaults2(BasicTextUI.java:370) at java.desktop/javax.swing.plaf.basic.BasicTextUI.installUI(BasicTextUI.java:805) at org.fife.ui.rtextarea.RTextAreaUI.installUI(RTextAreaUI.java:421) at java.desktop/javax.swing.JComponent.setUI(JComponent.java:740) at java.desktop/javax.swing.text.JTextComponent.setUI(JTextComponent.java:338) at org.fife.ui.rtextarea.RTextAreaBase.setRTextAreaUI(RTextAreaBase.java:1130) at org.fife.ui.rtextarea.RTextAreaBase.init(RTextAreaBase.java:656) at org.fife.ui.rtextarea.RTextArea.init(RTextArea.java:886) at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.init(RSyntaxTextArea.java:1996) at org.fife.ui.rtextarea.RTextAreaBase.<init>(RTextAreaBase.java:82) at org.fife.ui.rtextarea.RTextArea.<init>(RTextArea.java:181) at org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.<init>(RSyntaxTextArea.java:341) at net.sourceforge.squirrel_sql.plugins.syntax.rsyntax.SquirrelRSyntaxTextArea.<init>(SquirrelRSyntaxTextArea.java:56) at net.sourceforge.squirrel_sql.plugins.syntax.rsyntax.RSyntaxSQLEntryPanel.<init>(RSyntaxSQLEntryPanel.java:82) at net.sourceforge.squirrel_sql.plugins.syntax.rsyntax.RSyntaxSQLEntryAreaFactory.createSQLEntryPanel(RSyntaxSQLEntryAreaFactory.java:35) at net.sourceforge.squirrel_sql.plugins.syntax.SQLEntryPanelFactoryProxy.createSQLEntryPanel(SQLEntryPanelFactoryProxy.java:56) at net.sourceforge.squirrel_sql.client.session.mainpanel.SQLPanel.createGUI(SQLPanel.java:664) at net.sourceforge.squirrel_sql.client.session.mainpanel.SQLPanel.<init>(SQLPanel.java:144) at net.sourceforge.squirrel_sql.client.session.mainpanel.sqltab.SQLTab.createSqlPanel(SQLTab.java:26) at net.sourceforge.squirrel_sql.client.session.mainpanel.sqltab.BaseSQLTab.getComponent(BaseSQLTab.java:59) at net.sourceforge.squirrel_sql.client.gui.session.MainPanel.addMainPanelTab(MainPanel.java:177) at net.sourceforge.squirrel_sql.client.gui.session.MainPanel.<init>(MainPanel.java:98) at net.sourceforge.squirrel_sql.client.gui.session.SessionPanel.createGUI(SessionPanel.java:255) at net.sourceforge.squirrel_sql.client.gui.session.SessionPanel.initialize(SessionPanel.java:120) at net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame.createGUI(SessionInternalFrame.java:118) at net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame.<init>(SessionInternalFrame.java:52) at net.sourceforge.squirrel_sql.client.gui.WindowManager.createInternalFrame(WindowManager.java:337) at net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand$Runner.run(ConnectToAliasCommand.java:362) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at net.sourceforge.squirrel_sql.client.Main$1.dispatchEvent(Main.java:101) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:117) at java.desktop/java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:191) at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:236) at java.desktop/java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:234) at java.base/java.security.AccessController.doPrivileged(AccessController.java:319) at java.desktop/java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:234) at java.desktop/java.awt.Dialog.show(Dialog.java:1080) at java.desktop/java.awt.Component.show(Component.java:1728) at java.desktop/java.awt.Component.setVisible(Component.java:1675) at java.desktop/java.awt.Window.setVisible(Window.java:1036) at java.desktop/java.awt.Dialog.setVisible(Dialog.java:1016) at net.sourceforge.squirrel_sql.client.Application.showErrorDialog(Application.java:678) at net.sourceforge.squirrel_sql.client.mainframe.action.ConnectToAliasCommand$Runner.run(ConnectToAliasCommand.java:369) at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318) at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720) at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714) at java.base/java.security.AccessController.doPrivileged(AccessController.java:400) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87) at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742) at net.sourceforge.squirrel_sql.client.Main$1.dispatchEvent(Main.java:101) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109) at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

OS

`java.runtime.name OpenJDK Runtime Environment java.vm.version 21-ea+9-678 sun.boot.library.path C:\dev\jdk21\bin java.vm.vendor Oracle Corporation java.vendor.url https://java.oracle.com/ path.separator ; java.vm.name OpenJDK 64-Bit Server VM sun.os.patch.level
user.script user.country HU sun.java.launcher SUN_STANDARD java.vm.specification.name Java Virtual Machine Specification user.dir C:\dev\squirell java.vm.compressedOopsMode 32-bit java.runtime.version 21-ea+9-678 derby.system.home C:\Users\feher.squirrel-sql\plugins\derby os.arch amd64 java.io.tmpdir C:\Users\feher\AppData\Local\Temp\ line.separator

java.vm.specification.vendor Oracle Corporation user.variant
stderr.encoding cp852 os.name Windows 10 sun.jnu.encoding Cp1250 stdout.encoding cp852 java.library.path C:\dev\jdk21\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Users\feher\AppData\Local\Microsoft\WindowsApps;. jdk.debug release sun.awt.enableExtraMouseButtons true java.class.version 65.0 java.specification.name Java Platform API Specification sun.management.compiler HotSpot 64-Bit Tiered Compilers os.version 10.0 user.home C:\Users\feher user.timezone Europe/Budapest file.encoding UTF-8 java.specification.version 21 user.name
java.class.path squirrel-sql.jar java.vm.specification.version 21 sun.arch.data.model 64 sun.java.command squirrel-sql.jar java.home C:\dev\jdk21 user.language hu java.specification.vendor Oracle Corporation java.vm.info mixed mode, sharing java.version 21-ea native.encoding Cp1250 java.vendor Oracle Corporation file.separator \ java.version.date 2023-09-19 java.vendor.url.bug https://bugreport.java.com/bugreport/ sun.io.unicode.encoding UnicodeLittle sun.cpu.endian little sun.cpu.isalist amd64 ` https://github.com/squirrel-sql-client/squirrel-sql-code/issues/10

mps77 commented 1 year ago

reproduced with Hello example! https://github.com/bobbylight/RSyntaxTextArea/wiki/Example:-Hello,-RSyntaxTextArea

unnecessary blinkRate settings at

https://github.com/bobbylight/RSyntaxTextArea/blob/d0624d39e86e13b2d0d2865fcf2c37a7b7b92806/RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/RTextAreaUI.java#L172

later invoked by jdk at:

javax/swing/plaf/basic/BasicTextUI.java in installDefaults2()

`

private void installDefaults2() { editor.addMouseListener(dragListener); editor.addMouseMotionListener(dragListener);

    String prefix = getPropertyPrefix();

    Caret caret = editor.getCaret();
    if (caret == null || caret instanceof UIResource) {
        caret = createCaret();
        editor.setCaret(caret);

        int rate = DefaultLookup.getInt(getComponent(), this, prefix + ".caretBlinkRate", 500);
        caret.setBlinkRate(rate);
   }

`

thc202 commented 1 year ago

This is an issue in the JDK, it's already being fixed openjdk/jdk@e81f20b50405dc02963c8bf549000c60e78152d8.

bobbylight commented 1 year ago

As I mentioned in the linked PR, I merged this fix even though there is an OpenJDK fix. It addresses things in the specific bad OpenJDK versions, and the default value we were setting is (usually) overridden anyway by the LaF, so it's not necessary.