Modify

Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#22833 closed defect (fixed)

[Patch] Command line environment variables are overwritten by /etc/default/josm

Reported by: skyper Owned by: team
Priority: normal Milestone: 23.03
Component: Ubuntu package Version: latest
Keywords: template_report Cc: sebastic

Description (last modified by skyper)

What steps will reproduce the problem?

  1. Enter JAVA_OPTS="-Xmx256m -Djosm.home=/tmp/josm" josm in the console.

What is the expected result?

JOSM starts with appropriate assigned memory and JOSM dirs plus all environment variables set in /etc/default/josm and /usr/bin/josm

What happens instead?

All environment variables are present but the assigned memory value is taken from /etc/default/josm.

Please provide any additional information below. Attach a screenshot if possible.

Changing the order of the argument and the variable in /etc/default/josm seems to do the trick, e.g. JAVA_OPTS="${JAVA_OPTS} -Xmx768m" to JAVA_OPTS="-Xmx768m ${JAVA_OPTS}".

Relative:URL: ^/trunk
Repository:UUID: 0c6e7542-c601-0410-84e7-c038aed88b3b
Last:Changed Date: 2023-03-21 14:21:54 +0100 (Tue, 21 Mar 2023)
Revision:18698
Build-Date:2023-03-22 02:31:00
URL:https://josm.openstreetmap.de/svn/trunk

Identification: JOSM/1.5 (18698 en) Linux Debian GNU/Linux 11 (bullseye)
Memory Usage: 158 MB / 768 MB (41 MB allocated, but free)
Java version: 17.0.6+10-Debian-1deb11u1, Debian, OpenJDK 64-Bit Server VM
VM arguments: [--module-path=/usr/share/openjfx/lib, --add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web, -Djosm.restart=true, -Djosm.dir.name=JOSM-latest, -Djava.net.useSystemProxies=true, -Djosm.home=<josm.pref>, --add-exports=java.base/sun.security.action=ALL-UNNAMED, --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED, --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED]

Attachments (0)

Change History (6)

comment:1 by skyper, 21 months ago

Cc: sebastic added

comment:2 by sebastic, 21 months ago

JAVA_OPTS is an environment variable, not a commandline argument.

Commandline arguments are passed after the -jar option using $@:

        $JAVACMD $JAVA_OPTS -jar "${JOSM_PATH}" "$@"

By default none of the options in /etc/default/josm are enabled:

$ cat /etc/default/josm 
# Options to pass to java when starting JOSM.
# Uncomment the JAVA_OPTS lines to enable their use by /usr/bin/josm

# Increase usable memory
#JAVA_OPTS="${JAVA_OPTS} -Xmx2048m"

# Enable OpenGL pipeline (2D graphic accelerators)
#JAVA_OPTS="${JAVA_OPTS} -Dsun.java2d.opengl=True"

Using the environment variable works in this case:

$ JAVA_OPTS="-Xmx4096m" bash -x /usr/bin/josm --status-report
[...]
+ '[' -f /etc/default/josm ']'
+ . /etc/default/josm
+ JAVA_OPTS='-Djosm.restart=true -Djava.net.useSystemProxies=true -Xmx4096m'
[...]
+ /usr/lib/jvm/java-17-openjdk-amd64/bin/java --module-path /usr/share/openjfx/lib --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web -Djosm.restart=true -Djava.net.useSystemProxies=true -Xmx4096m --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED -jar /usr/share/josm/josm.jar --status-report
Revision:18678
Is-Local-Build:false
Build-Date:2023-03-03 06:09:07
Debian-Release:0.0.svn18678+dfsg-1~exp1
Build-Name:Debian

Identification: JOSM/1.5 (18678 Debian en) Linux Debian GNU/Linux 12 (bookworm)
Memory Usage: 250 MB / 4096 MB (230 MB allocated, but free)
Java version: 17.0.6+10-Debian-1, Debian, OpenJDK 64-Bit Server VM
[...]
VM arguments: [--module-path=/usr/share/openjfx/lib, --add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web, -Djosm.restart=true, -Djava.net.useSystemProxies=true, --add-exports=java.<user.name>e/sun.security.action=ALL-UNNAMED, --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED, --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED]
Program arguments: [--status-report]
[...]

Annoyingly --status-report doesn't exit like --version and --help.

Setting the same option in /etc/default/josm and the environment is conflicting:

$ grep ^JAVA_OPTS /etc/default/josm
JAVA_OPTS="${JAVA_OPTS} -Xmx2048m"
$ JAVA_OPTS="-Xmx4096m" bash -x /usr/bin/josm --status-report
[...]
+ '[' -f /etc/default/josm ']'
+ . /etc/default/josm
++ JAVA_OPTS='-Xmx4096m -Xmx2048m'
+ JAVA_OPTS='-Djosm.restart=true -Djava.net.useSystemProxies=true -Xmx4096m -Xmx2048m'
[...]
+ /usr/lib/jvm/java-17-openjdk-amd64/bin/java --module-path /usr/share/openjfx/lib --add-modules java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web -Djosm.restart=true -Djava.net.useSystemProxies=true -Xmx4096m -Xmx2048m --add-exports=java.base/sun.security.action=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED -jar /usr/share/josm/josm.jar --status-report
Revision:18678
Is-Local-Build:false
Build-Date:2023-03-03 06:09:07
Debian-Release:0.0.svn18678+dfsg-1~exp1
Build-Name:Debian

Identification: JOSM/1.5 (18678 Debian en) Linux Debian GNU/Linux 12 (bookworm)
Memory Usage: 248 MB / 2048 MB (228 MB allocated, but free)
Java version: 17.0.6+10-Debian-1, Debian, OpenJDK 64-Bit Server VM
[...]
VM arguments: [--module-path=/usr/share/openjfx/lib, --add-modules=java.scripting,java.sql,javafx.controls,javafx.media,javafx.swing,javafx.web, -Djosm.restart=true, -Djava.net.useSystemProxies=true, --add-exports=java.<user.name>e/sun.security.action=ALL-UNNAMED, --add-exports=java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED, --add-exports=java.desktop/com.sun.imageio.spi=ALL-UNNAMED]
Program arguments: [--status-report]
[...]

The last one is used as its value overwrites its predecessors.

I don't think this is a bug, either set the option in /etc/default/josm or set on the commandline.

A case can be made for prepending values to JAVA_OPTS like /usr/bin/josm to use value set by the user instead the one set by the administrator.

This patch could suffice:

diff --git a/native/linux/latest/etc/default/josm-latest b/native/linux/latest/etc/default/josm-latest
index ba09c29fc..dbd556ab6 100644
--- a/native/linux/latest/etc/default/josm-latest
+++ b/native/linux/latest/etc/default/josm-latest
@@ -2,8 +2,8 @@
 # Uncomment the JAVA_OPTS lines to enable their use by /usr/bin/josm-latest
 
 # Increase usable memory
-#JAVA_OPTS="${JAVA_OPTS} -Xmx2048m"
+#JAVA_OPTS="-Xmx2048m ${JAVA_OPTS}"
 
 # Enable OpenGL pipeline (2D graphic accelerators)
-#JAVA_OPTS="${JAVA_OPTS} -Dsun.java2d.opengl=True"
+#JAVA_OPTS="-Dsun.java2d.opengl=True ${JAVA_OPTS}"
 
diff --git a/native/linux/tested/etc/default/josm b/native/linux/tested/etc/default/josm
index 8cd8127f3..b646c4f3e 100644
--- a/native/linux/tested/etc/default/josm
+++ b/native/linux/tested/etc/default/josm
@@ -2,8 +2,8 @@
 # Uncomment the JAVA_OPTS lines to enable their use by /usr/bin/josm
 
 # Increase usable memory
-#JAVA_OPTS="${JAVA_OPTS} -Xmx2048m"
+#JAVA_OPTS="-Xmx2048m ${JAVA_OPTS}"
 
 # Enable OpenGL pipeline (2D graphic accelerators)
-#JAVA_OPTS="${JAVA_OPTS} -Dsun.java2d.opengl=True"
+#JAVA_OPTS="-Dsun.java2d.opengl=True ${JAVA_OPTS}"
 
Version 0, edited 21 months ago by sebastic (next)

comment:3 by skyper, 21 months ago

Summary: Command line arguments are overwritten by /etc/default/josm[Patch] Command line environment variables are overwritten by /etc/default/josm

comment:4 by skyper, 21 months ago

Description: modified (diff)

comment:5 by stoecker, 21 months ago

Resolution: fixed
Status: newclosed

In 18699/josm:

fix #22833 - reorder arguments to allow manual override - patch by sebastic

comment:6 by stoecker, 21 months ago

Milestone: 23.03

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.