Skip to content

Commit

Permalink
Fix trying to mutate maps that can be unmodifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Sep 10, 2024
1 parent 678243d commit 27bca5a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx4G
org.gradle.parallel=true

version=1.1.2
version=1.1.3

asm_version=9.7

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.util.HashMap;
import java.util.Map;

public class J_N_F_FileSystems {
Expand All @@ -17,6 +18,7 @@ public class J_N_F_FileSystems {
@CoverageIgnore
@Stub(ref = @Ref("java/nio/file/FileSystems"))
public static FileSystem newFileSystem(URI uri, Map<String, Object> env) throws IOException {
env = new HashMap<>(env);
env.replaceAll((k, v) -> {
if (v instanceof Boolean && !k.equals("useTempFile")) {
return v.toString();
Expand All @@ -29,6 +31,7 @@ public static FileSystem newFileSystem(URI uri, Map<String, Object> env) throws
@CoverageIgnore
@Stub(ref = @Ref("java/nio/file/FileSystems"))
public static FileSystem newFileSystem(URI uri, Map<String, Object> env, ClassLoader loader) throws IOException {
env = new HashMap<>(env);
env.replaceAll((k, v) -> {
if (v instanceof Boolean && !k.equals("useTempFile")) {
return v.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.spi.FileSystemProvider;
import java.util.HashMap;
import java.util.Map;

public class J_N_F_S_FileSystemProvider {

@Stub
@CoverageIgnore
public static FileSystem newFileSystem(FileSystemProvider provider, URI uri, Map<String, Object> env) throws IOException {
env = new HashMap<>(env);
env.replaceAll((k, v) -> {
if (v instanceof Boolean && !k.equals("useTempFile")) {
return v.toString();
Expand All @@ -27,6 +29,7 @@ public static FileSystem newFileSystem(FileSystemProvider provider, URI uri, Map
@Stub
@CoverageIgnore
public static FileSystem newFileSystem(FileSystemProvider provider, Path path, Map<String, Object> env) throws IOException {
env = new HashMap<>(env);
env.replaceAll((k, v) -> {
if (v instanceof Boolean && !k.equals("useTempFile")) {
return v.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Map;

import static java.nio.file.FileSystems.newFileSystem;

public class TestFile {

Expand All @@ -28,7 +34,15 @@ public static void main(String[] args) throws IOException {
}
reader.close();
System.out.println(sb.toString());

var temp2 = Files.createTempFile("temp", ".zip");
Files.deleteIfExists(temp2);
try (FileSystem fs = FileSystems.newFileSystem(temp2, Map.of("create", "true"))) {
Files.writeString(fs.getPath("/test.txt"), "Hello World!", StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}

Files.deleteIfExists(temp);
Files.deleteIfExists(temp2);
}

}

0 comments on commit 27bca5a

Please sign in to comment.