java.io.tmpdir on Mac JDK1.6

Diagnosing a test failure on a new machine today, I stumbled across this different behaviour in JDK1.6 on my Mac, running OSX10.6.6 where:

System.getProperty("java.io.tmpdir")

was returning a strange value of /var/folders/Ob/Ob-aqIAEG2WzgTa5ezd5qU+++TM/-Tmp-/ (note the plus characters) instead of the normal value of /tmp it used to return. Fortunately this property can also be set at on JVM start, by passing it in as an environment variable

-Djava.io.tmpdir=/tmp

4 comments

  1. Robert Watkins

    java.io.tmpdir isn’t required to be the same as $TEMP – it’s required to be a temporary directory that you don’t have to worry about the lifecycle of.

    Yeah, you can override it, but if you’re doing that because your application requires that behaviour, you may have other problems.

    (Not to mention hardcoding “/tmp” as an expected return value has other issues – /var/tmp is another common place in Unix land, and of course Windows uses its own crazy settings…)

  2. Pete

    If you wanted it to be /tmp, why bother referencing the property? Isn’t the point of having a property that the actual directory name is abstracted away?

    PG

  3. Patrick

    Thanks for both your comments.

    @Robert I understand that java.io.tmpdir doesn’t have to be the same as $TEMP. This was just an example I was using.

    @Pete I need a different value for this on my mac because we’re using a library that doesn’t handle the plus signs very well (known issue). Other people on our team don’t have this issue because they are using either windows or Linux.

  4. Simon Brunning

    It’s not a Java specific thing:

    Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import tempfile
    >>> tempfile.gettempdir()
    ‘/var/folders/3n/3n6gDs7kElCcizPaVaKKR++++TM/-Tmp-‘

Leave a Reply