Class SealedSystemProperties


  • public final class SealedSystemProperties
    extends java.lang.Object
    A snapshot of this JVM's System properties, taken once and never retaken, for configuration whose meaning must not change after an application has started.

    Why this exists

    System properties are writable by any code in the process, at any time. That was once checked -- System.setProperty required a PropertyPermission(..., "write") under a SecurityManager -- but SecurityManager was deprecated by JEP 411 and permanently disabled by JEP 486, so on a current JVM there is no check at all. Security configuration read live from System properties therefore means only what it meant at the instant it was read, and can be rewritten afterward by anything running in the same process.

    The platform solves this for itself the same way: the JVM keeps its own snapshot of the properties it was launched with, and several security-sensitive values (the serialization filter, the temporary directory, various TLS and RMI settings) are captured once and are simply not re-read. This class offers that to library and application code.

    When the snapshot is taken

    The snapshot is taken at the first call to get(), and there is exactly one for the lifetime of the JVM. Two consequences follow, and both matter:

    • Reading seals. get() is not a passive accessor; the first call fixes the snapshot as a side effect. Any consumer anywhere in the process can therefore be the one that seals, simply by consulting configuration.
    • Sealing is global. One snapshot serves every consumer, so they cannot disagree about what the properties were -- but equally, whoever reads first decides the instant for everyone.

    A deployment that wants to choose that instant should call seal() at the end of its own startup, once it has set every property it intends to set. seal() returns true if the call is what sealed the snapshot and false -- with a warning -- if something had already sealed it, which is worth attending to: it means the effective snapshot was taken at a moment the caller did not choose. isSealed() answers the same question without causing a seal.

    What this does and does not do

    It does not prevent anything. System.setProperty continues to work, and code that calls System.getProperty directly continues to see live values. What the snapshot provides is a source of configuration that a later write cannot alter, for the consumers that choose to read from it. Late writes are not rejected; they are invisible here.

    Nor does this class decide policy. It holds the properties; what to do when current configuration disagrees with them belongs to the consumer. EarliestOrNarrowestWhitelistManager is the one in this library today: it honors later changes that narrow a whitelist and ignores those that would widen it.

    MConfig.sealSystemProperties(), MConfig.getSealedSystemProperties() and MConfig.isSealedSystemProperties() forward to these methods, for callers who reach for MConfig first.

    A constraint on logging

    Initializing com.mchange.v2.log must never consult this class. Sealing reads configuration and logs what it did, so a logger that sealed in order to initialize would re-enter its own initialization. That is why MLog resolves its backend with a direct reflective construction rather than through a whitelist-gated one, and why the logger here is obtained lazily rather than in a static initializer.

    • Field Detail

      • NOTIONAL_RESOURCE_PATH

        public static final java.lang.String NOTIONAL_RESOURCE_PATH
        See Also:
        Constant Field Values
    • Method Detail

      • initSeal

        public static boolean initSeal​(java.util.List<DelayedLogItem> delayedLogItems)
        safe for use on/before mlog initialization pathway
      • isSealed

        public static boolean isSealed()
        safe for use on/before mlog initialization pathway
      • capCurrentThenSealed

        public static java.lang.String[] capCurrentThenSealed​(java.lang.String[] resources)
        safe for use on/before mlog initialization pathway
      • seal

        public static boolean seal()
        NOT safe for use on/before mlog initialization pathway