2

I have a WAR where a nasty library does things like System.setProperty("javax.xml.stream.XMLInputFactory", ...), which breaks the web server container, since the latter depends on the value of the same property (details here).

Before going through the tons of code misbehaving like that (yes, it's not even factorised), I'd like to check if there is some tool (eg, a special class loader) able to maintain WAR-level scope for at least writeable properties, so that these changes would remain in my web application and wouldn't interfere with the web container or other WARs.

zakmck
  • 2,715
  • 1
  • 37
  • 53
  • A war built on what framework? – Compass Apr 23 '19 at 20:53
  • @Compass, how is that relevant? Eventually, it's standard WAR under Tomcat or Jetty. Anyway, it's an API built with Spring + Maven. – zakmck Apr 23 '19 at 20:56
  • 1
    Can you file a bug report with the developer of that misbehaving library? Or, if it's open source, fix it yourself? – Robert Apr 23 '19 at 21:16
  • @Robert, legacy code, the developer has moved to someting else years ago. I'm able to fix it myself, but it implies rummaging through tens of files having that copy/pasted bad code. – zakmck Apr 23 '19 at 21:19
  • There is a lesson here: When using system properties, choose a distinct property name. For example, qualify the property name with the name of the package that uses it: "my.framework.compressStrings" instead of just "compressStrings". – Thomas Bitonti Apr 24 '19 at 14:02
  • @ThomasBitonti not really. `javax.xml.stream.XMLInputFactory` is pretty standard, you're supposed to use it if you want to change the XML parser to be used system-wide, but it should be changed from command line parameters or JVM config files, NOT hardwired in the code. Moreover, I know this and also your suggestion about naming app properties, the problem is there are pretty bad programmers out of my control. – zakmck Apr 24 '19 at 14:14
  • Sorry about that. Hardwiring an assignment to the property is the real problem. That is bad code. – Thomas Bitonti Apr 24 '19 at 14:24

1 Answers1

0

There is nothing that I am aware of that can be used to narrow the scope of system properties.

There is a lot of related information here: Scope of the Java System Properties

Thomas Bitonti
  • 1,179
  • 7
  • 14
  • Thanks, I had already read seen that and it's pretty clear those properties are on a per JVM instance level. – zakmck Apr 23 '19 at 20:58