import java.io.*;
import java.nio.file.*;
import java.util.zip.*;

public class ZipTest {
  public void m1(ZipEntry entry, File dir) {
    String name = entry.getName();
    File file = new File(dir, name);
    FileOutputStream os = new FileOutputStream(file); // ZipSlip
    RandomAccessFile raf = new RandomAccessFile(file, "rw"); // ZipSlip
    FileWriter fw = new FileWriter(file); // ZipSlip
  }

  public void m2(ZipEntry entry, File dir) {
    String name = entry.getName();
    File file = new File(dir, name);
    File canFile = file.getCanonicalFile();
    String canDir = dir.getCanonicalPath();
    if (!canFile.toPath().startsWith(canDir))
      throw new Exception();
    FileOutputStream os = new FileOutputStream(file); // OK
  }

  public void m3(ZipEntry entry, File dir) {
    String name = entry.getName();
    File file = new File(dir, name);
    if (!file.toPath().normalize().startsWith(dir.toPath()))
      throw new Exception();
    FileOutputStream os = new FileOutputStream(file); // OK
  }

  private void validate(File tgtdir, File file) {
    File canFile = file.getCanonicalFile();
    if (!canFile.toPath().startsWith(tgtdir.toPath()))
      throw new Exception();
  }

  public void m4(ZipEntry entry, File dir) {
    String name = entry.getName();
    File file = new File(dir, name);
    validate(dir, file);
    FileOutputStream os = new FileOutputStream(file); // OK
  }
}

@@ -1400,11 +1400,383 @@
 / OK%0A  %7D
+%0A%0A  public void m5(ZipEntry entry, File dir) %7B%0A    String name = entry.getName();%0A    File file = new File(dir, name);%0A    Path absfile = file.toPath().toAbsolutePath().normalize();%0A    Path absdir = dir.toPath().toAbsolutePath().normalize();%0A    if (!absfile.startsWith(absdir))%0A      throw new Exception();%0A    FileOutputStream os = new FileOutputStream(file); // OK%0A  %7D
 %0A%7D%0A

Add test for sanitization using toAbsolutePath().