From e49d4a9870c19f55a1d5473743880b415a8ead3c Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Wed, 22 Dec 2021 13:59:20 +0000 Subject: [PATCH] 8271447: java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters Reviewed-by: mgronlun --- .../jdk/jfr/internal/management/ChunkFilename.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/management/ChunkFilename.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/management/ChunkFilename.java index 236c980acd0..8cc2cfeb180 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/management/ChunkFilename.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/management/ChunkFilename.java @@ -74,7 +74,7 @@ public final class ChunkFilename { // If more than one file per second while (counter < MAX_CHUNK_NAMES) { - String extendedName = String.format("%s_%02d%s", filename, counter, FILE_EXTENSION); + String extendedName = makeExtendedName(filename, counter); p = directory.resolve(extendedName); counter++; if (!fileAcess.exists(p)) { @@ -83,4 +83,16 @@ public final class ChunkFilename { } throw new IOException("Unable to find unused filename after " + counter + " attempts"); } + + private String makeExtendedName(String filename, int counter) { + StringBuilder sb = new StringBuilder(); + sb.append(filename); + sb.append('_'); + if (counter < 10) { // chronological sorted + sb.append('0'); + } + sb.append(counter); + sb.append(FILE_EXTENSION); + return sb.toString(); + } }