• Post Reply Bookmark Topic Watch Topic
  • New Topic

Determining a System Property origin  RSS feed

 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to determine if a System property was overridden on the command line when the JVM was started? In other words, if I do something like:
System.getProperty("file.encoding")
is there a way to determine whether or not the returned value is from the JVM being started with a -Dfile.encoding=foo parameter?

I looked through the System and Runtime API docs, but didn't see anything that would help.

Thanks for the assistance.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there's not.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Maintain a set (java.util.Set) of all system properties that is populated at application start time (in your main method before anything else exists). This represents all system properties that were set with -D but without the distinction between the usual system properties that always appear (see API spec. for System.getProperties).

2. Use bytecode enhancement to intercept all calls to System.setProperty after application start - unfortunately you can't use a Proxy (since the method does not exist on an interface where it should).
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for your replies.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!