From 06d8dcf8847579c6a68ac40f180f7527271d23d6 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 16 Oct 2026 04:45:37 +0200 Subject: [PATCH] Improve EditorKit injection warning for platform users - add migration path to the warning to make it more useful for platform or plugin developers - 'nb.disable.editorkit.hack' can now be used to disable the kit injection including the warning - the default value of the flag will be set true in future first, before subsequent removal of the code --- .../netbeans/modules/editor/EditorModule.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ide/editor/src/org/netbeans/modules/editor/EditorModule.java b/ide/editor/src/org/netbeans/modules/editor/EditorModule.java index eb8f3f0848ca..4c12a3330915 100644 --- a/ide/editor/src/org/netbeans/modules/editor/EditorModule.java +++ b/ide/editor/src/org/netbeans/modules/editor/EditorModule.java @@ -145,9 +145,18 @@ public void saveSetting(String settingName, Object value) { initAndCheckEditorKitTypeRegistry("text/html", HTMLEditorKit.class.getName()); //NOI18N initAndCheckEditorKitTypeRegistry("text/rtf", RTFEditorKit.class.getName()); //NOI18N initAndCheckEditorKitTypeRegistry("application/rtf", RTFEditorKit.class.getName()); //NOI18N - + // Now hook up to the JDK's editor kit registry - // XXX: This all should be removed, see IZ #80110 + // TODO: This all should be removed, see IZ #80110 or #9523 + if (!Boolean.parseBoolean(System.getProperty("nb.disable.editorkit.hack", "false" /*TODO true in future*/))) { + LOG.log(Level.WARNING, + """ + Setting content type by mime type String for NetBeans editor kits is no longer supported and will fail on JDK 27 and later, obtain the EditorKit instead: + jtextarea.setContentType("text/x-properties") => + jtextarea.setEditorKit(CloneableEditorSupport.getEditorKit("text/x-properties")) + Set the sytem property 'nb.disable.editorkit.hack=true' to disable this warning. + """ + ); try { Field keyField = JEditorPane.class.getDeclaredField("kitRegistryKey"); // NOI18N keyField.setAccessible(true); @@ -166,21 +175,10 @@ public void saveSetting(String settingName, Object value) { // Hashtable kitMapping = (Hashtable)sun.awt.AppContext.getAppContext().get(key); // sun.awt.AppContext.getAppContext().put(key, new HackMap(kitMapping)); } catch (Throwable t) { - if (debug) { - LOG.log(Level.WARNING, "Can't hack in to the JEditorPane's registry for kits.", t); - } else { - LOG.log(Level.WARNING, "Can''t hack in to the JEditorPane''s registry for kits: {0}", new Object[] {t}); - } + LOG.log(Level.WARNING, "Can't hack in to the JEditorPane's registry to replace editor kits."); } - - // Registration of the editor kits to JEditorPane -// for (int i = 0; i < replacements.length; i++) { -// JEditorPane.registerEditorKitForContentType( -// replacements[i].contentType, -// replacements[i].newKitClassName, -// getClass().getClassLoader() -// ); -// } + } + // removeme end // ------------------------------------------------------------