karakun / OpenWebStart

Run Web Start based applications after the release of Java 11
https://openwebstart.com
Other
428 stars 46 forks source link

user.dir should point to a directory owned by the user executring the application #361

Closed elbosso closed 3 years ago

elbosso commented 4 years ago

When an application is started via openwebstart, the SystemProperty "user.dir" should point to a directory owned by the user who initiated that applications execution - or at least in a directory where said user has read/write privileges.

Some applications assume this and try to create files in the current working directory - one notable example being JasperReports:

net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Error saving expressions class file: /opt/OpenWebStart/sQLshell__generated__design_1606490862466_624354.java.
        at net.sf.jasperreports.engine.design.JRAbstractCompiler.getSourceFile(JRAbstractCompiler.java:325)
        at net.sf.jasperreports.engine.design.JRAbstractCompiler.createCompileUnit(JRAbstractCompiler.java:291)
        at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:179)
        at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:357)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:617)
        at de.netsysit.util.jasper.Utilities.generateReport(Utilities.java:364)
        at de.netsysit.util.jasper.ReportPreviewer.run(ReportPreviewer.java:78)
        at de.netsysit.util.threads.Synchronizer.run(Synchronizer.java:19)
        at de.netsysit.util.threads.ThreadManagerHelper.run(ThreadManagerHelper.java:43)
Caused by: net.sf.jasperreports.engine.JRException: Error saving expressions class file: /opt/OpenWebStart/sQLshell__generated__design_1606490862466_624354.java.
        at net.sf.jasperreports.engine.util.JRSaver.saveClassSource(JRSaver.java:174)
        at net.sf.jasperreports.engine.design.JRAbstractCompiler.getSourceFile(JRAbstractCompiler.java:321)
        ... 8 more
Caused by: java.io.FileNotFoundException: /opt/OpenWebStart/sQLshell__generated__design_1606490862466_624354.java (Permission denied)
        at java.base/java.io.FileOutputStream.open0(Native Method)
        at java.base/java.io.FileOutputStream.open(FileOutputStream.java:298)
        at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:237)
        at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:187)
        at java.base/java.io.FileWriter.<init>(FileWriter.java:96)
        at net.sf.jasperreports.engine.util.JRSaver.saveClassSource(JRSaver.java:166)
        ... 9 more

This problem (and many similar ones) would disappear if the SystemProperty "user.dir" would be set as mentioned above

sclassen commented 3 years ago

According to the Oracle Java spec The user.dir points to the location the application was called from (i.e. the current working directory). Thus it may or may not be writable by the user. The question is what the current working directory is for an application which was launched by double clicking a shortcut or by opening a link in a web browser...

But in any case it is not a good practice to make any assumptions about the current working dir

elbosso commented 3 years ago

Well, ok lets say the oracle spec is a bit unclear on this point. However: user.dir is the current working dir and at times where webstart came from sun, oracle an later on icedtea it always was the users home directory. It is not that uncommon to expect a java desktop application - and webstart apps are exactly that from a users perspective - to start with a current working dir that belongs to the user executing it. The obvious suspect in that case being that users home directory.

Believe me - I came not here to get lectured about good programming practice. I came here because I thought I found a way to prolong the life of java applications that bet on webstart. When i stumbled onto OpenWebstart i naturally assumed it would try and behave like the original webstart as a drop in replacement - if that is not the case, please state so clearly on the Website and the github readme!

FelixJongleur42 commented 3 years ago

I agree with you from the compatibility perspective. Regardless on how useful „user.dir“ is, OWS should try and mimic Oracles behavior as closely as possible.

janakmulani commented 3 years ago

Some observations on Windows:

Oracle JWS : Dbl-Clk On JNLP : user.dir = dir in which JNLP is contained. Oracle JWS : Rt-Clk Open with On JNLP : user.dir = c:\windows\system32 Oracle JWS : From commandline >javaws : user.dir = current dir when javaws command was invoked

OWS : All of above cases : user.dir = OWS installation dir where OWS javaws.exe is contained.

Thanks for pointing this out.

We will discuss and create an issue to track internally - either to fix or to document.

sclassen commented 3 years ago

fixed in 1.3.2