'MacOS different behavior of native print Dialog when using 'save as PDF' feature between built application and started application from IDE

I am using OpenJDK16 (Liberica 16.0.2).

Here is my little Program:

public class PrintBugDemoGradle {
    public static void main(String[] args) throws Throwable {
        EventQueue.invokeAndWait(() -> {
            try {
                var job = PrinterJob.getPrinterJob();

                var attrs = new HashPrintRequestAttributeSet();
                attrs.add(DialogTypeSelection.NATIVE);

                if (!job.printDialog(attrs))
                    return;

                var book = new Book();
                book.append(
                        (g, pageFormat, pageIndex) -> {
                            g.drawString(
                                    "Hello, world!",
                                    (int) ceil(pageFormat.getImageableX()),
                                    (int) ceil(pageFormat.getImageableY() + g.getFont().getSize2D())
                            );
                            return Printable.PAGE_EXISTS;
                        },
                        job.getPageFormat(attrs)
                );
                job.setPageable(book);

                job.print(attrs);
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}

When running this code in Windows everything ist fine. When running this code out of the IDE in Mac OS X (in this case 10.14.6) everything is also fine. When building this code into an .app package and running it. I get the following exception when using the "Save as PDF" Feature of the native Dialog( "PDF"Button on the below lefthand corner of the native Dialog) after I selected the Path where the PDF finally should be printed:

Cannot write to file: /localhost/Users/Entwicklung/Desktop/testForStackoverflow.pdf
    at java.desktop/sun.print.RasterPrinterJob.validateDestination(RasterPrinterJob.java:1692)

I noticed that when I runnig the code out of the IDE the path would be /Users/Entwicklung/Desktop/testForStackoverflow.pdf -> which is correct

I really do not know why the native Dialog adds localhost as prefix to the path only when im running it as .app package

Here is my Info.plist in hope the problem can be found here:

<?xml version="1.0" ?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSEnvironment</key>
<dict>
<key>LC_CTYPE</key>
<string>UTF-8</string>
</dict>
<key>JVMConfig</key>
<dict>
<key>MainClass</key>
<string>PrintBugDemoGradle</string>
<key>ClassPath</key>
<array>
<string>$JAVAROOT/PrintBugDemoGradle-1.0.jar</string>
</array>
<key>JVMVersion</key>
<string>1.16+</string>
<key>JVMRuntime</key>
<string>1.16.0.jdk</string>
<key>JVMOptions</key>
<array>
</array>
<key>WorkingDirectory</key>
<string>$APP_PACKAGE/Contents/Resources</string>
</dict>
</dict>
</plist>




Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source