Skip to content

Commit

Permalink
fix print writer ctor stack
Browse files Browse the repository at this point in the history
fixes #10
  • Loading branch information
wagyourtail committed Jul 14, 2024
1 parent dc889e5 commit 416d4e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package xyz.wagyourtail.downgradetest;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

public class TestPrintWriter {


public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(System.out, false, StandardCharsets.UTF_8);
out.println("Hello World!");

var temp = Files.createTempFile("temp", "txt");
out = new PrintWriter(temp.toAbsolutePath().toString(), StandardCharsets.UTF_8);
out.println("Hello World!");
out.close();

out = new PrintWriter(temp.toFile(), StandardCharsets.UTF_8);
out.println("Goodbye World!");
out.close();

Files.deleteIfExists(temp);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ public static void init(MethodNode mnode, int i) {
list.add(new TypeInsnNode(Opcodes.NEW, "java/io/BufferedWriter"));
// stack: PrintWriter, boolean, OutputStreamWriter, (U) BufferedWriter
list.add(new InsnNode(Opcodes.DUP_X2));
// stack: PrintWriter, boolean, (U) BufferedWriter, OutputStreamWriter, (U) BufferedWriter
// stack: PrintWriter, (U) BufferedWriter, boolean, OutputStreamWriter, (U) BufferedWriter
list.add(new InsnNode(Opcodes.SWAP));
// stack: PrintWriter, boolean, (U) BufferedWriter, (U) BufferedWriter, OutputStreamWriter
// stack: PrintWriter, (U) BufferedWriter, boolean, (U) BufferedWriter, OutputStreamWriter
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/io/BufferedWriter", "<init>", "(Ljava/io/Writer;)V", false));
// stack: PrintWriter, boolean, BufferedWriter
list.add(new InsnNode(Opcodes.SWAP));
// stack: PrintWriter, BufferedWriter, boolean
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/io/PrintWriter", "<init>", "(Ljava/io/Writer;Z)V", false));

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/xyz/wagyourtail/jvmdg/test/ClassRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ public void testRuntime(String mainClass, FlagsAndRunner javaVersion) throws IOE
}

public static void compareResults(String mainClass, FlagsAndRunner javaVersion, Map.Entry<Integer, String> originalResult, Map.Entry<Integer, String> downgradedResult) {
assertEquals(originalResult.getKey(), downgradedResult.getKey(), "Exit code mismatch for " + mainClass + " on " + javaVersion.readableSlug());
assertEquals(originalResult.getValue(), downgradedResult.getValue(), "Output mismatch for " + mainClass + " on " + javaVersion.readableSlug());
assertEquals(originalResult.getKey(), downgradedResult.getKey(), "Exit code mismatch for " + mainClass + " on " + javaVersion.readableSlug());
}

public record FlagsAndRunner(Flags flags, JavaRunner.JavaVersion targetVersion) {
Expand Down

0 comments on commit 416d4e8

Please sign in to comment.