21

I'm using _JAVA_OPTIONS to set some defaults for Java on RHEL. It works fine but now every time I start java I get the following message

 Picked up _JAVA_OPTIONS: -foo -bar -baz

is it possible to keep the options but suppress the display of this message.

3 Answers3

15

Java is often called with absolute paths like /usr/bin/java, which makes this answer useless in some cases, and requires more to make it work in others.

That solution I found requires writing a wrapper shell script that redirects STDERR through a filter removing the offending line. It has to be placed in the $PATH before the java binary it wraps and be called with plain java, which java or similar (or your tool has to be configured to use it)

It relies on the bash ability to create a subshell with parentheses (command), and redirect java’s STDERR to its STDIN command1 2> >(command2). Finally, the process in the subshell needs to redirect its filtered input to STDOUT again so that java programs can still use STDERR.

#!/bin/bash
/usr/bin/java "$@" 2> >(grep -v "^Picked up _JAVA_OPTIONS:" >&2)
4

Or you can put this in your shell startup / profile files:

_SILENT_JAVA_OPTIONS="$_JAVA_OPTIONS"
unset _JAVA_OPTIONS
alias java='java "$_SILENT_JAVA_OPTIONS"'
spelufo
  • 171
2

This message is output by all standard versions of Java since (I think Java 5). It is certainly present in the source code from Java 6 through Java 15.

It is output by the java command when it sees that the JAVA_TOOL_OPTIONS or _JAVA_OPTIONS environment variable is set and when the user is not privileged. The behavior is hardwired, and the java command doesn't provide a way to suppress it. (If you want more precise details, look at the arguments.cpp file.)

People have requested that Oracle add an option to suppress the message:

JDK-8039152 : Need a way to suppress message when picking up JAVA_TOOL_OPTIONS

but this has been closed as WON'T FIX.


First of all, it is important to understand why this message is output. According to bug report's analysis:

"So that leaves adding an option to suppress the message. Yes, we could do this, but is it a good idea? The reason that the message is issued is that the feature being used is dangerous and the VM should warn about it.

I strongly recommend that we don't try to change this behavior. 03-04-2014"

In short, the message is a WARNING that something potentially dangerous may be happening. Something that could cause java to behave in unexpected (and possibly even insecure) ways.


So what can you do to make the annoying message go away?

The best solution is to not use those variables. Unset them! There are other ways to pass command options to the java command that are less dangerous. If the annoying output is coming from some application that relies on those variables ... raise a bug report for the application.

There are other possible solutions; e.g. filtering the message out of the error stream, or expanding JAVA_TOOL_OPTIONS into the java command line (see other answers).

  • I recommend that you DO NOT do either of these things. Why? Because by suppressing the message you are disabling an important safety feature in the java command.

  • And if you do decide to suppress the message, DO NOT do it by replacing the standard java command with a shell alias or a wrapper script. That is really asking for trouble.

kjsmita6
  • 105
Stephen C
  • 445