1

I have a large legacy application written in Java 15 with Swing and JavaFX using the Netbeans 14 Platform. So when the application starts, it looks like Netbeans IDE and has the IDE menu items, for this question, the File -> Open File...

enter image description here

We are transitioning to files an order of magnitude bigger than in the past (over 1G of text) so it throws an exception (not surprisingly) when loading that file. It looks like the exception happens when Netbeans (openide) tries to load the file into a text pane. I haven't decided how to resolve this, but for now, I would like to just display a statistics panel. Here is the exception:

INFO [org.openide.text.DataEditorSupport]: UIHANDLER_TOO_BIG_FILE_LOADED
SEVERE [org.openide.util.Exceptions]
java.lang.NegativeArraySizeException: -2147483648
    at org.netbeans.modules.editor.lib2.document.ReadWriteUtils.read(ReadWriteUtils.java:51)
    at org.netbeans.editor.BaseDocument.read(BaseDocument.java:1459)
    at org.netbeans.editor.BaseKit.read(BaseKit.java:663)
    at org.openide.text.DataEditorSupport.loadFromStreamToKit(DataEditorSupport.java:457)
    at org.openide.text.DocumentOpenClose$DocumentLoad.atomicLockedRun(DocumentOpenClose.java:739)
    at org.openide.text.DocumentOpenClose$DocumentLoad.run(DocumentOpenClose.java:590)
    at org.netbeans.editor.GuardedDocument.runAtomic(GuardedDocument.java:296)
    at org.openide.text.NbDocument.runAtomic(NbDocument.java:411)
    at org.openide.text.DocumentOpenClose$DocumentLoad.run(DocumentOpenClose.java:630)
    at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1418)
    at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
    at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
[catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
WARNING [org.netbeans.core.TimableEventQueue]: too much time in AWT thread null

Note that the whole stack trace is netbeans and openide classes, none of our stuff.

The first "at" line is a link, which when clicked, gives the error

Source not found for "ReadWriteUtils"

I have downloaded the source and javadoc jars from https://repository.apache.org/#nexus-search;quick~openide and attempted to tell Netbeans where they are so I can figure out how to interrupt the loading of the file so it doesn't try to display it all. I have placed the jars into a directory and exploded them into the org tree so I can see the sources. I then went to Tools -> Netbeans Platforms to open up the Netbeans Platform Manager. Under the "Development IDE" platform, I select Sources and click on the "Add ZIP/Folder..." button. I won't let me select any of the jars, but when I select the org directory, it add it to the Platform Sources. When I select Javadoc and click the "Add ZIP/Folder..." button, it allows me to select the javadoc jars. enter image description here

Note that the some jars have RELEASE140 in their name and some don't. I copied one and removed it to see if it may have confused Netbeans.

No dice. I suspect that Netbeans has its own version of the class files jars somewhere and so is ignoring my attempts to tell it where the source code is. Is the openide version the Netbeans is using different than RELEASE140? Here is the the top part of the modules list:

INFO [org.netbeans.core.startup.NbEvents]: Turning on modules:
    slf4j.jdk14 [1.7.28 1.7.28]
    slf4j.api [1.7.28 1.7.28]
    org.openide.util.lookup [8.49 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.util [9.23 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.util.ui [9.24 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.modules [7.63 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.annotations.common/1 [1.43 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.filesystems [9.27 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.awt [7.83 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.progress/1 [1.63 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.progress.nb [1.63 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.dialogs [7.57 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.nodes [7.60 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.windows [6.92 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.libs.batik.read [1.8.0.1 1 Netbeans/netbeans-TLP/netbeans/release130-20-on-20220221]
    org.openide.util.ui.svg [1.9 Netbeans/netbeans-TLP/netbeans/release130-20-on-20220221]
    org.netbeans.modules.editor.mimelookup/1 [1.55 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.text [6.83 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.scripting [1.12 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.swing.tabcontrol [1.71 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.swing.outline [1.49 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.explorer [6.77 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.actions [6.54 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.modules.queries/1 [1.58 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.templates [1.23 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.filesystems.nb [9.25 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.loaders [7.85 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.intent [1.17 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.api.io [1.18 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.io [1.64 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.filesystems.compat8 [9.24 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.execution [9.18 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.openide.execution.compat8 [9.17 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.swing.plaf [1.57 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]
    org.netbeans.modules.keyring [1.39 13-00d6d969bf4d9b14e7406c9ee9cc13a61dc39655]

I also added the jars to C:\Program Files\NetBeans-14\netbeans\platform\docs because I found some JUnit jars there. That had no apparent effect.

I would like to be able to bring up the openide source to put in breakpoints and view what it is doing before it hits the exception. So my question is, how do I view the openide source code in Netbeans?

Of course the real goal is to replace the processing of the file by ReadWriteUtils with our own and to that end, I have been working through the tutorials at https://netbeans.apache.org//kb/docs/platform.html. So far, none of them are helping me with this.

AlexHomeBrew
  • 117
  • 9

1 Answers1

0

It's simpler than that.

In order to be able to debug your application, including when it runs the Netbeans platform code, just download netbeans-14-source.zip from the Apache Netbeans 14 download page, then go to menu Tools/Netbeans platform, and add the .zip file in the source tab.

Now if you add a breakpoint in your application code when it calls a Netbeans platform code, you'll be able to step inside the Netbeans code as well and debug it.

To add a breakpoint from a specific Netbeans platform file (ReadWriteUtils.java in your case): menu open File, select the netbeans-14-source.zip then your file, and add the breakpoint.

Also, Netbeans will automatically retrieve the javadoc from the source files. To see it, menu Windows/IDE tools/Java doc

jjazzboss
  • 1,261
  • 8
  • 14
  • I had high hopes for this but it doesn't seem to work for me. I downloaded the jar, put it in E:/apache/lib and added it to the Tools -> Netbeans Platform -> Sources tab. I also removed everything else from that tab. Still, when I open a class it tells me "No sources found." If I click on the Attach Sources... link, (the title is Attach Sources to "org-openide-filesystems-RELEASE140.jar") and "Add Zip/Folder" it fills in that pane with 1506 lines similar to: ide/db/src/ in E:\apache\lib\netbeans-14-source.zip. Sometimes that works and sometimes it doesn't. – AlexHomeBrew Aug 11 '22 at 16:55
  • And it doesn't preserve that list when opening another file or when restarting Netbeans. – AlexHomeBrew Aug 11 '22 at 16:57
  • Note that I tried exploding the zip file (101k+ files) into a directory and tried referencing that in the Sources tab. No dice. The java files are there, I can find them and edit them but Netbeans doesn't seem to recognize them. – AlexHomeBrew Aug 11 '22 at 17:02
  • Why org-opeinde-filesystems-RELEASE140.jar ?? You don't anything else besides the netbeans-14-source.zip file. Check also which Netbeans platform your project uses. Go to your project (I assume it's a module suite) and check its properties -> libraries -> Netbeans Platform. – jjazzboss Aug 11 '22 at 19:10
  • I assume that is because my pom.xml has a dependency on org-openide-filesystems. I was wondering if that is the source of my problems, Netbeans can't make the connection between the jar and the sources. If I install the zip file as the source and remove all of the jars, will Netbeans have to compile everything each time I do a clean build? – AlexHomeBrew Aug 11 '22 at 21:12
  • The jar has classes in their packages, like org/openide/filesystems/RepositoryListener.class. The zip file has the java file in platform/openide.filesystems/src/org/openide/filesystems/RepositoryListener.java. Could that be why Netbeans isn't correlating the two? – AlexHomeBrew Aug 11 '22 at 21:19
  • By the way, I inherited all this code and am still learning it. There are 18 interrelated projects and none of them have a 'libraries' selection in the properties. there are other signs that this code may not be "modularized". How can I tell? – AlexHomeBrew Aug 11 '22 at 21:35