How to debug Java UNO in LibreOffice? - java

I have been researching on the topic for a couple of days and wrote a simple UNO component to work with the Spreadsheet. The main challenge I faced during the process is whenever the LO cannot find a class (i.e. some required jar is not included in the oxt package), the thread dies absolutely silently without throwing any exception. The only way to find out is to step trace all the suspecious code which is both frustrating and very time consuming. Only then can I see the exception message text and exception itself being created. Unfortunately, this exception is never really thrown in the environment I have or is silenced in some way.
Is there any way to enable LO to throw exceptions/see stack trace for debug purposes? Is there any location where LP puts java console output?
Any help is very much appreciated!

If you have not done so yet, I recommend getting the BookmarkInsertion example to work. Be sure that the application can find the main 4 jars in the classpath: juh.jar, jurt,jar, ridl,jar, unoil.jar.
Are you running the component from the Java IDE, for example, NetBeans?
Normally, build errors and exceptions are reported in the appropriate output window at the bottom of the IDE, and this is where java console output appears as well.
Otherwise, if you have already installed the OXT file in LibreOffice and are running it without a Java IDE, then there is no console output displayed. In that case, you may want to log to a file with something like log4j. However, error messages may still be able to pop up in a message box, depending on the error.
EDIT:
For an example in Eclipse, I followed the instructions at https://github.com/LibreOffice/loeclipse. To show messages:
Window -> Show View -> Console
Window -> Show View -> Error Log
When I renamed jurt.jar to jurt0.jar so that it cannot be found, then the following was shown in the Console pane.
Exception in thread "Thread-8" java.lang.ClassNotFoundException:
com.sun.star.comp.loader.JavaLoader
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
System.err.println also writes to the Console pane. I modified ActionOneDialog.java as follows.
public void show() {
System.err.println("show() BEGIN");
dialog.execute();
System.err.println("show() END");
}

Related

NetBeans IDE 12.5 no Project Open

I'm running NetBeans IDE 12.5 with Java 1.8.0_311 on Mac OS 11.16 Big Sur.
No Folders are displayed in the Projects Window, no difference with new created or old projects.
I already adjusted the netbeans.conf to the right JDK home directory:
netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.8.0_311.jdk/Contents/Home"
Also I get an Unexpected Exception - java.lang.NullPointerException in the notifications when trying to open a project.
Full trace:
java.lang.NullPointerException
at org.netbeans.modules.j2ee.metadata.model.api.support.annotation.AnnotationModelHelper.runJavaSourceTaskWhenScanFinished(AnnotationModelHelper.java:190)
at org.netbeans.modules.j2ee.dd.impl.webservices.annotation.WebservicesMetadataModelImpl.runReadActionWhenReady(WebservicesMetadataModelImpl.java:80)
at org.netbeans.modules.j2ee.metadata.model.api.MetadataModel.runReadActionWhenReady(MetadataModel.java:160)
at org.netbeans.modules.websvc.core.jaxws.projects.JavaEEWSOpenHook.projectOpened(JavaEEWSOpenHook.java:80)
at org.netbeans.spi.project.ui.ProjectOpenedHook$1.projectOpened(ProjectOpenedHook.java:60)
at org.netbeans.spi.project.ui.support.UILookupMergerSupport$OpenHookImpl.projectOpened(UILookupMergerSupport.java:223)
at org.netbeans.spi.project.ui.ProjectOpenedHook$1.projectOpened(ProjectOpenedHook.java:60)
[catch] at org.netbeans.modules.project.ui.OpenProjectList.notifyOpened(OpenProjectList.java:1323)
at org.netbeans.modules.project.ui.OpenProjectList.access$1600(OpenProjectList.java:116)
at org.netbeans.modules.project.ui.OpenProjectList$LoadOpenProjects.loadOnBackground(OpenProjectList.java:513)
at org.netbeans.modules.project.ui.OpenProjectList$LoadOpenProjects.run(OpenProjectList.java:384)
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)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
I found a similar question on stack overflow where adjusting the config file was mentioned as a possible solution.
Output from IDE Log:
WARNING [org.netbeans.modules.options.keymap.LayersBridge]: Invalid shortcut: org.openide.loaders.XMLDataObject#20e83598[MultiFileObject#19d29edf[Actions/Help/master-help.xml]]
WARNING [org.netbeans.modules.options.keymap.LayersBridge]: Invalid shortcut: org.openide.loaders.BrokenDataShadow#72ee9bcd[MultiFileObject#58de53e0[Keymaps/NetBeans/D-BACK_QUOTE.shadow]]
WARNING [null]: Last record repeated again.
Any other ideas?
Thanks!

IntelliJ 2019.2.2: Unable to debug gradle unit tests

Every time I try to debug one of my tests (junit 5), I get an exception:
2019-12-20 10:40:53,776 [4972237] WARN - .ExternalSystemTaskDebugRunner - Interrupted function call: accept failed
java.net.SocketException: Interrupted function call: accept failed
at java.base/java.net.PlainSocketImpl.accept0(Native Method)
at java.base/java.net.PlainSocketImpl.socketAccept(PlainSocketImpl.java:159)
at java.base/java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:458)
at java.base/java.net.ServerSocket.implAccept(ServerSocket.java:551)
at java.base/java.net.ServerSocket.accept(ServerSocket.java:519)
at com.intellij.openapi.externalSystem.service.execution.ForkedDebuggerThread.run(ForkedDebuggerThread.java:103)
I've done quite a bit of searching through SO here, and have found several people that had similar problems. Most of them were resolve simply by upgrading (to 2013 or whatever, these questions aren't exactly spring chickens). The rest required some special sauce relevant to their system (android stuff mostly). Or they're getting a different exception (being disconnected, where I'm never getting the connection in the first place).
These tests (unit tests for the most part) are attached to a module with no "main".
I've tried launching gradlew -DtestDebug.test=true cleanTest test, and then connect with a remote debug session. I get an error: Unable to open debugger port (localhost:5005); java.net.ConnectException "Connection refused: connect", which I believe is just what IntelliJ's gui shows when it receives the aforementioned exception.
Ideally, I'd like to set my breakpoints, debug-launch my test task (perhaps specifying a class or individual #Test), and it'd Just Work.
Does anyone have any other ideas I could try? Logs I could look at?
The workaround is to switch the build/run actions to IntelliJ IDEA instead of using Gradle.
But if you still have this issue in the current IDE version, please consider reporting it with the sample project and the logs (Help | Compress Logs and Show in ...) attached.

Java Exception has occurred when opening .JAR file

I am trying to run a jar file that came with a program designed by BOSCH called EsiTronic. I receive the following error message "A java exception has occurred" I made some research and looked in the other threds of this forum but it did not help me. My gues is that the version I am using is not supporting the version the program was compiled on. I tried running it from CMD to see the detailed error message. If someone can tell me more from this message I will apreciate. I want to point out I am not a programer so my knoledge is limited here.
Thanks!
Exception in thread "main" java.lang.ClassFormatError: Truncated class file
Exception in thread "main" java.lang.ClassFormatError: Truncated class file
Theres nothing much that you can do here except re-download the jar file. The jar file probably got curropted during download or even at the time of packaging from the source

UnsatisfiedLinkError and NoClassDefFoundError : Running Java Mapscript on Ubuntu 11.10

We have coded and run a dynamic web application using MAPSERVER(Version 6.0.1) on windows platform using Java Technology. Now, there is need of deploying it on Ubuntu 11.10. We have installed Apache Tomcat 6.0, Mapserver 6.0.1, Apache 2.0, and FWTools-2.0.1(As this package contain all required tools for mapserver if I am not wrong, so I didn't feel any other tools to be installed). We have deployed the war file(and put application without) in Apache Tomcat 's Webapps folder. I even got the index page which dont have code related with mapscript api. But while fetching the other servlet with mapscript we are getting following error...
java.lang.UnsatisfiedLinkError: no mapscript in java.library.path
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
java.lang.Runtime.loadLibrary0(Runtime.java:840)
java.lang.System.loadLibrary(System.java:1047)
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)
Again while refreshing the browser page where the above error was displayed, I got a change,
java.lang.NoClassDefFoundError: Could not initialize class
edu.umn.gis.mapscript.mapscriptJNI
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)
I searched on net about the above problem. But finally blank. Please, provide idea about the above problem.
I'm not going to explain why you're getting the UnsatisfiedLinkError, but instead I'll explain why you are getting the NoClassDefFoundError when you reload the page.
A NoClassDefFoundError with a message Could not initialize class ... is thrown by the JVM when it attempts to initialize a class that it has already tried and failed to initialize.
The first of your two stacktraces contains the line
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
The method name <clinit> denotes the static initializer, of the class mapscriptJNI. So, at the point that the UnsatisfiedLinkError was thrown, the JVM was trying to initialize this class. Looking at the error message, it seems that this static initializer tried to load the native code library mapscript but failed.
This UnsatisfiedLinkError causes the mapscriptJNI class to fail to initialize successfully. The JVM keeps a record of all classes that fail to initialize, and if you attempt to initialize one of those classes again, you'll get a NoClassDefFoundError with a message saying that it could not initialize that class.
When you refresh the page, you end up causing the JVM to attempt to initialize the class mapscriptJNI a second time. Of course, this class failed to initialize the previous time. Your second stacktrace contains exactly the error I've described.
In short, the UnsatisfiedLinkError is the real error here. Fix that and the other one will go away.
I would check the following 2 items:
Is the mapscript.jar file on Tomcat or at least your webapp's classpath? (NoClassDefFoundError is your big clue here)
Is the libmapscript.so on either your LD_LIBRARY_PATH or -Djava.library.path? (UnsatisfiedLinkError since the shared object cannot be found)
Try having a look at this post, near the Running Java Mapscript (on Linux) section.
Hope that helps!

Minecraft Coders Pack Errors when Running in Eclipse

Okay I am trying to make minecraft mods using eclipse. I used this video to set it up. I added both ModLoader and GuiApi to the Jar files before decompiling. It works until I try to test it in Eclipse then I get these errors:
Failed to load mod from "mod_HeroesGuild.class"
Exception in thread "Minecraft main thread" java.lang.ExceptionInInitializerError
at net.minecraft.client.Minecraft.startGame(Minecraft.java:140)
at net.minecraft.client.Minecraft.run(Minecraft.java:438)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at net.minecraft.src.CanvasMojangLogo.<init>(CanvasMojangLogo.java:22)
at net.minecraft.src.PanelCrashReport.<init>(PanelCrashReport.java:103)
at net.minecraft.src.MinecraftImpl.displayUnexpectedThrowable(MinecraftImpl.java:26)
at net.minecraft.src.ModLoader.ThrowException(ModLoader.java:1612)
at net.minecraft.src.ModLoader.init(ModLoader.java:714)
at net.minecraft.src.ModLoader.AddAllRenderers(ModLoader.java:121)
at net.minecraft.src.RenderManager.<init>(RenderManager.java:72)
at net.minecraft.src.RenderManager.<clinit>(RenderManager.java:168)
... 3 more
I am new to programming and I don't have any idea what to do...
The run system starts minecraft the mojang logo appears but then I get a white screen! Thanks!
I found a forum where someone had the same error:
http://www.minecraftforum.net/topic/236195-crashing-after-mojang-logo-problem-solved/
The answer they give is to reinstall, via instructions at:
http://www.minecraftwiki.net/wiki/Tutorials/Minecraft_Help_FAQ#Reinstalling_Minecraft
...and the poster replies:
didn't think to delete the whole .minecraft.
Problem cured.
Remember to back it up first.
Underlying cause
I'm thinking your SDK is somehow loading from/conflicting with your existing Minecraft install.
This is because .minecraft is the folder under the Application Data folder that contains minecraft user/runtime data. Basically, your save game data, and the program's cached data.

Categories