Search code examples
javasystem-properties

Missing java.compiler system property


I'm using Java 8. According to the docs, the system property java.compiler should be present. However when I run even a basic class, it's not.

import java.util.Comparator;
import java.util.Map;

public class SystemPropertiesPrinter {

    public static void main(String[] args) {
        Map<String, String> properties = (Map) System.getProperties(); // It's a pain to sort without this artificial cast
        properties.entrySet().stream()
                .sorted(Comparator.comparing(Map.Entry::getKey))
                .forEach(e -> System.out.printf("%-30s -> %s%n", e.getKey(), e.getValue()));
    }

}

I run it with the following command:

java SystemPropertiesPrinter

And here's the result:

awt.toolkit                    -> sun.awt.windows.WToolkit
file.encoding                  -> Cp1252
file.encoding.pkg              -> sun.io
file.separator                 -> \
java.awt.graphicsenv           -> sun.awt.Win32GraphicsEnvironment
java.awt.printerjob            -> sun.awt.windows.WPrinterJob
java.class.path                -> .
java.class.version             -> 52.0
java.endorsed.dirs             -> C:\Program Files\Java\jdk1.8.0_66\jre\lib\endorsed
java.ext.dirs                  -> C:\Program Files\Java\jdk1.8.0_66\jre\lib\ext;C:\Windows\Sun\Java\lib\ext
java.home                      -> C:\Program Files\Java\jdk1.8.0_66\jre
java.io.tmpdir                 -> C:\dev\cygwin64\tmp\
java.library.path              -> <edited out>
java.runtime.name              -> Java(TM) SE Runtime Environment
java.runtime.version           -> 1.8.0_66-b18
java.specification.name        -> Java Platform API Specification
java.specification.vendor      -> Oracle Corporation
java.specification.version     -> 1.8
java.vendor                    -> Oracle Corporation
java.vendor.url                -> http://java.oracle.com/
java.vendor.url.bug            -> http://bugreport.sun.com/bugreport/
java.version                   -> 1.8.0_66
java.vm.info                   -> mixed mode
java.vm.name                   -> Java HotSpot(TM) 64-Bit Server VM
java.vm.specification.name     -> Java Virtual Machine Specification
java.vm.specification.vendor   -> Oracle Corporation
java.vm.specification.version  -> 1.8
java.vm.vendor                 -> Oracle Corporation
java.vm.version                -> 25.66-b18
line.separator                 ->

os.arch                        -> amd64
os.name                        -> Windows 7
os.version                     -> 6.1
path.separator                 -> ;
sun.arch.data.model            -> 64
sun.boot.class.path            -> <edited out>
sun.boot.library.path          -> C:\Program Files\Java\jdk1.8.0_66\jre\bin
sun.cpu.endian                 -> little
sun.cpu.isalist                -> amd64
sun.desktop                    -> windows
sun.io.unicode.encoding        -> UnicodeLittle
sun.java.command               -> SystemPropertiesPrinter
sun.java.launcher              -> SUN_STANDARD
sun.jnu.encoding               -> Cp1252
sun.management.compiler        -> HotSpot 64-Bit Tiered Compilers
sun.os.patch.level             -> Service Pack 1
user.country                   -> GB
user.dir                       -> C:\Users\olivier\tmp
user.home                      -> C:\Users\olivier
user.language                  -> en
user.name                      -> olivier
user.script                    ->
user.timezone                  ->
user.variant                   ->

As you can see, the property java.compiler is absent from my list. Is this normal? Shouldn't it be present, if we refer to the docs, especially as it's not marked as "depecrated"? This question states that this property can take specific value, but it mentions nowhere that it can be absent.


Solution

  • According to the docs, the system property java.compiler should be present

    No, this is not what the doc says.

    From the doc:

    The current set of system properties for use by the getProperty(String) method is returned as a Properties object. If there is no current set of system properties, a set of system properties is first created and initialized. This set of system properties always includes values for the following keys [...]

    The doc says that if no set of properties is defined a new one will be generated. The generated one will always have the properties listed in the docs. Not all sets will have them, just the one that is generated by that class. If the system already has a properties set, you aren't guaranteed to find all those keys in it.