• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Determining a System Property origin  RSS feed

 
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.
 
author and iconoclast
Posts: 24203
43
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, there's not.
 
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.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!