You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Emmeran Seehuber (JIRA)" <ji...@apache.org> on 2018/07/08 17:08:00 UTC

[jira] [Commented] (PDFBOX-4013) Java 9/macOS: Debugger App does not start (NoSuchMethodException)

    [ https://issues.apache.org/jira/browse/PDFBOX-4013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16536342#comment-16536342 ] 

Emmeran Seehuber commented on PDFBOX-4013:
------------------------------------------

For JDK9+ it is possible (and the preferred way) to use the Deskop.getDesktop().setXYHandler(). None of the gist's were using this. In the attached patch [^pdfdebugger-macos-fixes_v1.patch] I used reflection to set the the event handlers. Beside this I did some future stuff in the patch:
 * Allow printing on macOS. I see no reason not to allow it, it least it works for me. No, there is no global printing menu (at least not on macOS High Sierra, no idea why it was disabled in the first place).
 * Removed duplicate code in the exit handlers. There was one for the menu events and one for the window event.
 * Fixed opening files on macOS. FileDialog.getFile() only returns the file name without the pathname.
 * Made this class more friendly to be embedded into other applications. I'm already using the PDFDebugger in on of my  applications as my application handles many PDF files and PDFDebugger is very nice to take quick look into a PDF. Currently I manually remove the window listener (which would quit the whole java application when closing the window ...) and because my application is already on JDK 10 the global event handler is not set. I made two protected methods performApplicationExit() and initGlobalEventHandlers() which can be overridden when embedding the PDFDebugger in another application to just be NOP's. I think this is better than an additional constructor parameter, but if you think an explicit parameter would be better (as it would document the fact that you can embed the PDFDebugger) I'll change that.

As a side node: Theoretically osxOpenFiles() should work as it works on JDK <= 8. But in practice it does nothing on all JDKs. The file open event handlers are only called when an application is bundled. On macOS bundled applications are special named directories with some "magic" config files and all application files in there.  You can look up details here [https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html] if you are interested. To have PDFDebugger receive those events it would be required to build such an application bundle. As I've done this already for an application of mine I could also build one for the PDFDebugger. But this only would make sense if the PDFDebugger application would be downloadable on the download page in form of a .dmg image. It's possible to create such .dmg images on other plattforms (see [https://stackoverflow.com/questions/286419/how-to-build-a-dmg-mac-os-x-file-on-a-non-mac-platform)] but I am not sure if this is worth the hassle. But macOS applications can of course also be delivered as .zip files, it's just not the "native" way to deliver applications. When not delivering the PDFDebugger as application bundle the osxOpenFiles() method (and all related stuff in OSXAdapter) is just unreachable code and could be deleted.

Also OSXAdapter has two unused methods (setAboutHandler(), setPreferencesHandler()). As long as the PDFDebugger does not get a preference or about dialog those two could just be deleted.

Tested on macOS 10.13.5 with JDK 8, 9 and 10.

> Java 9/macOS: Debugger App does not start (NoSuchMethodException)
> -----------------------------------------------------------------
>
>                 Key: PDFBOX-4013
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4013
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.0.8
>            Reporter: Emmeran Seehuber
>            Priority: Major
>              Labels: jdk9, mac-os-x
>         Attachments: pdfdebugger-macos-fixes_v1.patch
>
>
> It seems the debugger app wants to integrate nicely into macOS and uses some private API for this. This worked fine with all Java versions including 8, but does no longer work with 9.
> Java 9 provides new APIs for this, but till PDFBox can depend on Java 9 (or the next LTS Java 11) it should at least catch this and not crash....
> The application does not start, and instead displays a dialog with a stack trace.
> Console Output + StackTrace:
> {code}
> WARNING: An illegal reflective access operation has occurred
> WARNING: Illegal reflective access by org.apache.pdfbox.debugger.ui.OSXAdapter (file:/Users/emmy/Downloads/debugger-app-2.0.7.jar) to constructor com.apple.eawt.Application()
> WARNING: Please consider reporting this to the maintainers of org.apache.pdfbox.debugger.ui.OSXAdapter
> WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
> WARNING: All illegal access operations will be denied in a future release
> Mac OS X Adapter could not talk to EAWT:
> java.lang.RuntimeException: java.lang.NoSuchMethodException: com.apple.eawt.Application.addApplicationListener(com.apple.eawt.ApplicationListener)
>     org.apache.pdfbox.debugger.ui.OSXAdapter.setHandler(OSXAdapter.java:171)
>     org.apache.pdfbox.debugger.ui.OSXAdapter.setFileHandler(OSXAdapter.java:137)
>     org.apache.pdfbox.debugger.PDFDebugger.initComponents(PDFDebugger.java:301)
>     org.apache.pdfbox.debugger.PDFDebugger.<init>(PDFDebugger.java:182)
>     org.apache.pdfbox.debugger.PDFDebugger.main(PDFDebugger.java:1201)
> Caused by: java.lang.NoSuchMethodException: com.apple.eawt.Application.addApplicationListener(com.apple.eawt.ApplicationListener)
>     java.base/java.lang.Class.getDeclaredMethod(Class.java:2432)
>     org.apache.pdfbox.debugger.ui.OSXAdapter.setHandler(OSXAdapter.java:163)
>     org.apache.pdfbox.debugger.ui.OSXAdapter.setFileHandler(OSXAdapter.java:137)
>     org.apache.pdfbox.debugger.PDFDebugger.initComponents(PDFDebugger.java:301)
>     org.apache.pdfbox.debugger.PDFDebugger.<init>(PDFDebugger.java:182)
>     org.apache.pdfbox.debugger.PDFDebugger.main(PDFDebugger.java:1201)
> {code}
> To workaround this problem I have to run the debugger app using JDK 8. This is ok for now, but very annoying.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org