Merge branch 'stable-2.12'

* stable-2.12:
  xdocs: Fix a race condition in generating the temporary file name

Change-Id: Id20a678f7216cb42f9e173f2af759c41cdfc98f0
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/AsciidoctorFormatter.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/AsciidoctorFormatter.java
index 8bbe7a0..caa31c4 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/AsciidoctorFormatter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/formatter/AsciidoctorFormatter.java
@@ -75,8 +75,9 @@
         formatters.getFormatterConfig(NAME, projectName);
     // asciidoctor ignores all attributes if no output file is specified,
     // this is why we must specify an output file and then read its content
-    File tmpFile =
-        new File(baseDir, "tmp/asciidoctor-" + TimeUtil.nowTs().getNanos() + ".tmp");
+    File tmpDir = new File(baseDir, "tmp");
+    tmpDir.mkdirs();
+    File tmpFile = File.createTempFile("asciidoctor-", null, tmpDir);
     try {
       Asciidoctor.Factory.create(AsciidoctorFormatter.class.getClassLoader())
           .render(raw, createOptions(projectCfg, abbrRev, tmpFile));