8327474: Review use of java.io.tmpdir in jdk tests
Reviewed-by: michaelm, jpai
This commit is contained in:
parent
233619b3fb
commit
375bfac8e7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -41,6 +41,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jdk.test.lib.process.ProcessTools;
|
import jdk.test.lib.process.ProcessTools;
|
||||||
import sun.tools.attach.HotSpotVirtualMachine;
|
import sun.tools.attach.HotSpotVirtualMachine;
|
||||||
@ -53,7 +54,7 @@ public class CheckOrigin {
|
|||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
// start a process that has options set in a number of different ways
|
// start a process that has options set in a number of different ways
|
||||||
|
|
||||||
File flagsFile = File.createTempFile("CheckOriginFlags", null);
|
File flagsFile = File.createTempFile("CheckOriginFlags", null, Path.of(".").toFile());
|
||||||
try (PrintWriter pw =
|
try (PrintWriter pw =
|
||||||
new PrintWriter(new FileWriter(flagsFile))) {
|
new PrintWriter(new FileWriter(flagsFile))) {
|
||||||
pw.println("+PrintCodeCache");
|
pw.println("+PrintCodeCache");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -362,13 +362,13 @@ public class CheckPermission {
|
|||||||
"getFileSystemAttributes");
|
"getFileSystemAttributes");
|
||||||
|
|
||||||
prepare();
|
prepare();
|
||||||
File tmpFile = File.createTempFile(CHECK_PERMISSION_TEST, null);
|
File tmpFile = File.createTempFile(CHECK_PERMISSION_TEST, null, new File("."));
|
||||||
assertOnlyCheckOperation(tmpFile, EnumSet.of(FileOperation.WRITE));
|
assertOnlyCheckOperation(tmpFile, EnumSet.of(FileOperation.WRITE));
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
assertCheckOperation(tmpFile, EnumSet.of(FileOperation.DELETE));
|
assertCheckOperation(tmpFile, EnumSet.of(FileOperation.DELETE));
|
||||||
|
|
||||||
prepare();
|
prepare();
|
||||||
tmpFile = File.createTempFile(CHECK_PERMISSION_TEST, null, null);
|
tmpFile = File.createTempFile(CHECK_PERMISSION_TEST, null, new File("."));
|
||||||
assertOnlyCheckOperation(tmpFile, EnumSet.of(FileOperation.WRITE));
|
assertOnlyCheckOperation(tmpFile, EnumSet.of(FileOperation.WRITE));
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
assertCheckOperation(tmpFile, EnumSet.of(FileOperation.DELETE));
|
assertCheckOperation(tmpFile, EnumSet.of(FileOperation.DELETE));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -46,28 +46,31 @@ public class NegativeAvailable {
|
|||||||
|
|
||||||
// Create a temporary file with size of 10 bytes.
|
// Create a temporary file with size of 10 bytes.
|
||||||
Path tmp = Files.createTempFile(null, null);
|
Path tmp = Files.createTempFile(null, null);
|
||||||
try (BufferedWriter writer =
|
try {
|
||||||
Files.newBufferedWriter(tmp, Charset.defaultCharset())) {
|
try (BufferedWriter writer =
|
||||||
for (int i = 0; i < SIZE; i++) {
|
Files.newBufferedWriter(tmp, Charset.defaultCharset())) {
|
||||||
writer.write('1');
|
for (int i = 0; i < SIZE; i++) {
|
||||||
|
writer.write('1');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
File tempFile = tmp.toFile();
|
File tempFile = tmp.toFile();
|
||||||
try (FileInputStream fis = new FileInputStream(tempFile)) {
|
try (FileInputStream fis = new FileInputStream(tempFile)) {
|
||||||
if (tempFile.length() != SIZE) {
|
if (tempFile.length() != SIZE) {
|
||||||
throw new RuntimeException("unexpected file size = "
|
throw new RuntimeException("unexpected file size = "
|
||||||
+ tempFile.length());
|
+ tempFile.length());
|
||||||
|
}
|
||||||
|
long space = skipBytes(fis, SKIP, SIZE);
|
||||||
|
space = skipBytes(fis, NEGATIVE_SKIP, space);
|
||||||
|
space = skipBytes(fis, SKIP, space);
|
||||||
|
space = skipBytes(fis, SKIP, space);
|
||||||
|
space = skipBytes(fis, SKIP, space);
|
||||||
|
space = skipBytes(fis, NEGATIVE_SKIP, space);
|
||||||
|
space = skipBytes(fis, NEGATIVE_SKIP, space);
|
||||||
}
|
}
|
||||||
long space = skipBytes(fis, SKIP, SIZE);
|
} finally {
|
||||||
space = skipBytes(fis, NEGATIVE_SKIP, space);
|
Files.deleteIfExists(tmp);
|
||||||
space = skipBytes(fis, SKIP, space);
|
|
||||||
space = skipBytes(fis, SKIP, space);
|
|
||||||
space = skipBytes(fis, SKIP, space);
|
|
||||||
space = skipBytes(fis, NEGATIVE_SKIP, space);
|
|
||||||
space = skipBytes(fis, NEGATIVE_SKIP, space);
|
|
||||||
}
|
}
|
||||||
Files.deleteIfExists(tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -159,13 +159,17 @@ public class Bind {
|
|||||||
});
|
});
|
||||||
// address with space should work
|
// address with space should work
|
||||||
checkNormal(() -> {
|
checkNormal(() -> {
|
||||||
server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
UnixDomainSocketAddress usa = UnixDomainSocketAddress.of("with space");
|
||||||
UnixDomainSocketAddress usa = UnixDomainSocketAddress.of("with space"); // relative to CWD
|
|
||||||
Files.deleteIfExists(usa.getPath());
|
Files.deleteIfExists(usa.getPath());
|
||||||
server.bind(usa);
|
try {
|
||||||
client = SocketChannel.open(usa);
|
server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
||||||
Files.delete(usa.getPath());
|
// relative to CWD
|
||||||
assertAddress(client.getRemoteAddress(), usa, "address");
|
server.bind(usa);
|
||||||
|
client = SocketChannel.open(usa);
|
||||||
|
assertAddress(client.getRemoteAddress(), usa, "address");
|
||||||
|
} finally {
|
||||||
|
Files.deleteIfExists(usa.getPath());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// client bind to null: allowed
|
// client bind to null: allowed
|
||||||
checkNormal(() -> {
|
checkNormal(() -> {
|
||||||
@ -185,12 +189,19 @@ public class Bind {
|
|||||||
});
|
});
|
||||||
// server bind to null: should bind to a local address
|
// server bind to null: should bind to a local address
|
||||||
checkNormal(() -> {
|
checkNormal(() -> {
|
||||||
server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
UnixDomainSocketAddress usa = null;
|
||||||
server.bind(null);
|
try {
|
||||||
UnixDomainSocketAddress usa = (UnixDomainSocketAddress)server.getLocalAddress();
|
server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
||||||
if (usa.getPath().toString().isEmpty())
|
server.bind(null);
|
||||||
throw new RuntimeException("expected non zero address length");
|
usa = (UnixDomainSocketAddress) server.getLocalAddress();
|
||||||
System.out.println("Null server address: " + server.getLocalAddress());
|
if (usa.getPath().toString().isEmpty())
|
||||||
|
throw new RuntimeException("expected non zero address length");
|
||||||
|
System.out.println("Null server address: " + server.getLocalAddress());
|
||||||
|
} finally {
|
||||||
|
if (usa != null) {
|
||||||
|
Files.deleteIfExists(usa.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// server no bind : not allowed
|
// server no bind : not allowed
|
||||||
checkException(
|
checkException(
|
||||||
@ -307,23 +318,32 @@ public class Bind {
|
|||||||
Arrays.fill(chars, 'x');
|
Arrays.fill(chars, 'x');
|
||||||
String name = new String(chars);
|
String name = new String(chars);
|
||||||
UnixDomainSocketAddress address = UnixDomainSocketAddress.of(name);
|
UnixDomainSocketAddress address = UnixDomainSocketAddress.of(name);
|
||||||
ServerSocketChannel server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
try {
|
||||||
server.bind(address);
|
ServerSocketChannel server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
||||||
SocketChannel client = SocketChannel.open(address);
|
server.bind(address);
|
||||||
assertAddress(server.getLocalAddress(), address, "server");
|
SocketChannel client = SocketChannel.open(address);
|
||||||
assertAddress(client.getRemoteAddress(), address, "client");
|
assertAddress(server.getLocalAddress(), address, "server");
|
||||||
Files.delete(address.getPath());
|
assertAddress(client.getRemoteAddress(), address, "client");
|
||||||
|
} finally {
|
||||||
|
Files.deleteIfExists(address.getPath());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// implicit server bind
|
// implicit server bind
|
||||||
checkNormal(() -> {
|
checkNormal(() -> {
|
||||||
server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
UnixDomainSocketAddress usa = null;
|
||||||
server.bind(null);
|
try {
|
||||||
UnixDomainSocketAddress usa = (UnixDomainSocketAddress)server.getLocalAddress();
|
server = ServerSocketChannel.open(StandardProtocolFamily.UNIX);
|
||||||
client = SocketChannel.open(usa);
|
server.bind(null);
|
||||||
accept1 = server.accept();
|
usa = (UnixDomainSocketAddress) server.getLocalAddress();
|
||||||
assertAddress(client.getRemoteAddress(), usa, "server");
|
client = SocketChannel.open(usa);
|
||||||
Files.delete(usa.getPath());
|
accept1 = server.accept();
|
||||||
|
assertAddress(client.getRemoteAddress(), usa, "server");
|
||||||
|
} finally {
|
||||||
|
if (usa != null) {
|
||||||
|
Files.deleteIfExists(usa.getPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,8 +29,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.StandardProtocolFamily;
|
import java.net.StandardProtocolFamily;
|
||||||
|
import java.net.UnixDomainSocketAddress;
|
||||||
import java.nio.channels.ServerSocketChannel;
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
import jtreg.SkippedException;
|
import jtreg.SkippedException;
|
||||||
|
|
||||||
public class NonBlockingAccept {
|
public class NonBlockingAccept {
|
||||||
@ -48,17 +51,23 @@ public class NonBlockingAccept {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
||||||
checkSupported();
|
checkSupported();
|
||||||
|
UnixDomainSocketAddress addr = null;
|
||||||
|
|
||||||
try (ServerSocketChannel serverSocketChannel =
|
try (ServerSocketChannel serverSocketChannel =
|
||||||
ServerSocketChannel.open(StandardProtocolFamily.UNIX)) {
|
ServerSocketChannel.open(StandardProtocolFamily.UNIX)) {
|
||||||
//non blocking mode
|
//non blocking mode
|
||||||
serverSocketChannel.configureBlocking(false);
|
serverSocketChannel.configureBlocking(false);
|
||||||
serverSocketChannel.bind(null);
|
serverSocketChannel.bind(null);
|
||||||
|
addr = (UnixDomainSocketAddress) serverSocketChannel.getLocalAddress();
|
||||||
SocketChannel socketChannel = serverSocketChannel.accept();
|
SocketChannel socketChannel = serverSocketChannel.accept();
|
||||||
System.out.println("The socketChannel is : expected Null " + socketChannel);
|
System.out.println("The socketChannel is : expected Null " + socketChannel);
|
||||||
if (socketChannel != null)
|
if (socketChannel != null)
|
||||||
throw new RuntimeException("expected null");
|
throw new RuntimeException("expected null");
|
||||||
// or exception could be thrown otherwise
|
// or exception could be thrown otherwise
|
||||||
|
} finally {
|
||||||
|
if (addr != null) {
|
||||||
|
Files.deleteIfExists(addr.getPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -40,41 +40,47 @@ import java.util.zip.ZipEntry;
|
|||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 8184940 8188869
|
* @bug 8184940 8188869
|
||||||
* @summary JDK 9 rejects zip files where the modified day or month is 0
|
* @summary JDK 9 rejects zip files where the modified day or month is 0
|
||||||
* or otherwise represent an invalid date, such as 1980-02-30 24:60:60
|
* or otherwise represent an invalid date, such as 1980-02-30 24:60:60
|
||||||
* @author Liam Miller-Cushon
|
* @author Liam Miller-Cushon
|
||||||
|
* @library /test/lib
|
||||||
*/
|
*/
|
||||||
public class ZeroDate {
|
public class ZeroDate {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// create a zip file, and read it in as a byte array
|
// create a zip file, and read it in as a byte array
|
||||||
Path path = Files.createTempFile("bad", ".zip");
|
Path path = Utils.createTempFile("bad", ".zip");
|
||||||
try (OutputStream os = Files.newOutputStream(path);
|
try {
|
||||||
ZipOutputStream zos = new ZipOutputStream(os)) {
|
try (OutputStream os = Files.newOutputStream(path);
|
||||||
ZipEntry e = new ZipEntry("x");
|
ZipOutputStream zos = new ZipOutputStream(os)) {
|
||||||
zos.putNextEntry(e);
|
ZipEntry e = new ZipEntry("x");
|
||||||
zos.write((int) 'x');
|
zos.putNextEntry(e);
|
||||||
}
|
zos.write((int) 'x');
|
||||||
int len = (int) Files.size(path);
|
}
|
||||||
byte[] data = new byte[len];
|
int len = (int) Files.size(path);
|
||||||
try (InputStream is = Files.newInputStream(path)) {
|
byte[] data = new byte[len];
|
||||||
is.read(data);
|
try (InputStream is = Files.newInputStream(path)) {
|
||||||
}
|
is.read(data);
|
||||||
Files.delete(path);
|
}
|
||||||
|
|
||||||
// year, month, day are zero
|
// year, month, day are zero
|
||||||
testDate(data.clone(), 0, LocalDate.of(1979, 11, 30).atStartOfDay());
|
testDate(data.clone(), 0, LocalDate.of(1979, 11, 30).atStartOfDay());
|
||||||
// only year is zero
|
// only year is zero
|
||||||
testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5).atStartOfDay());
|
testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5).atStartOfDay());
|
||||||
// month is greater than 12
|
// month is greater than 12
|
||||||
testDate(data.clone(), 0 << 25 | 13 << 21 | 1 << 16, LocalDate.of(1981, 1, 1).atStartOfDay());
|
testDate(data.clone(), 0 << 25 | 13 << 21 | 1 << 16, LocalDate.of(1981, 1, 1).atStartOfDay());
|
||||||
// 30th of February
|
// 30th of February
|
||||||
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16, LocalDate.of(1980, 3, 1).atStartOfDay());
|
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16, LocalDate.of(1980, 3, 1).atStartOfDay());
|
||||||
// 30th of February, 24:60:60
|
// 30th of February, 24:60:60
|
||||||
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16 | 24 << 11 | 60 << 5 | 60 >> 1,
|
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16 | 24 << 11 | 60 << 5 | 60 >> 1,
|
||||||
LocalDateTime.of(1980, 3, 2, 1, 1, 0));
|
LocalDateTime.of(1980, 3, 2, 1, 1, 0));
|
||||||
|
} finally {
|
||||||
|
Files.delete(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testDate(byte[] data, int date, LocalDateTime expected) throws IOException {
|
private static void testDate(byte[] data, int date, LocalDateTime expected) throws IOException {
|
||||||
@ -86,7 +92,7 @@ public class ZeroDate {
|
|||||||
writeU32(data, locpos + LOCTIM, date);
|
writeU32(data, locpos + LOCTIM, date);
|
||||||
|
|
||||||
// ensure that the archive is still readable, and the date is 1979-11-30
|
// ensure that the archive is still readable, and the date is 1979-11-30
|
||||||
Path path = Files.createTempFile("out", ".zip");
|
Path path = Utils.createTempFile("out", ".zip");
|
||||||
try (OutputStream os = Files.newOutputStream(path)) {
|
try (OutputStream os = Files.newOutputStream(path)) {
|
||||||
os.write(data);
|
os.write(data);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
package jdk.jfr.api.consumer.filestream;
|
package jdk.jfr.api.consumer.filestream;
|
||||||
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -35,6 +34,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
import jdk.jfr.Event;
|
import jdk.jfr.Event;
|
||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.consumer.EventStream;
|
import jdk.jfr.consumer.EventStream;
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -148,7 +148,7 @@ public class TestOrdered {
|
|||||||
e.join();
|
e.join();
|
||||||
}
|
}
|
||||||
r.stop();
|
r.stop();
|
||||||
Path p = Files.createTempFile("recording", ".jfr");
|
Path p = Utils.createTempFile("recording", ".jfr");
|
||||||
r.dump(p);
|
r.dump(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -34,6 +34,7 @@ import jdk.jfr.Event;
|
|||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.consumer.EventStream;
|
import jdk.jfr.consumer.EventStream;
|
||||||
import jdk.jfr.consumer.RecordedEvent;
|
import jdk.jfr.consumer.RecordedEvent;
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -118,7 +119,7 @@ public class TestReuse {
|
|||||||
}
|
}
|
||||||
r.stop();
|
r.stop();
|
||||||
rotation.close();
|
rotation.close();
|
||||||
Path p = Files.createTempFile("recording", ".jfr");
|
Path p = Utils.createTempFile("recording", ".jfr");
|
||||||
r.dump(p);
|
r.dump(p);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,6 +35,7 @@ import jdk.jfr.consumer.RecordedEvent;
|
|||||||
import jdk.jfr.consumer.RecordedThread;
|
import jdk.jfr.consumer.RecordedThread;
|
||||||
import jdk.jfr.consumer.RecordingFile;
|
import jdk.jfr.consumer.RecordingFile;
|
||||||
import jdk.test.lib.Asserts;
|
import jdk.test.lib.Asserts;
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
@ -78,7 +79,7 @@ public class TestManyVirtualThreads {
|
|||||||
}
|
}
|
||||||
|
|
||||||
r.stop();
|
r.stop();
|
||||||
Path p = Files.createTempFile("test", ".jfr");
|
Path p = Utils.createTempFile("test", ".jfr");
|
||||||
r.dump(p);
|
r.dump(p);
|
||||||
long size = Files.size(p);
|
long size = Files.size(p);
|
||||||
Asserts.assertLessThan(size, 100_000_000L, "Size of recording looks suspiciously large");
|
Asserts.assertLessThan(size, 100_000_000L, "Size of recording looks suspiciously large");
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -44,42 +44,48 @@ import java.util.Collections;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
|
||||||
/* @test
|
/* @test
|
||||||
* @bug 8184940 8186227 8188869
|
* @bug 8184940 8186227 8188869
|
||||||
* @summary JDK 9 rejects zip files where the modified day or month is 0
|
* @summary JDK 9 rejects zip files where the modified day or month is 0
|
||||||
* or otherwise represent an invalid date, such as 1980-02-30 24:60:60
|
* or otherwise represent an invalid date, such as 1980-02-30 24:60:60
|
||||||
* @author Liam Miller-Cushon
|
* @author Liam Miller-Cushon
|
||||||
* @modules jdk.zipfs
|
* @modules jdk.zipfs
|
||||||
|
* @library /test/lib
|
||||||
*/
|
*/
|
||||||
public class ZeroDate {
|
public class ZeroDate {
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// create a zip file, and read it in as a byte array
|
// create a zip file, and read it in as a byte array
|
||||||
Path path = Files.createTempFile("bad", ".zip");
|
Path path = Utils.createTempFile("bad", ".zip");
|
||||||
try (OutputStream os = Files.newOutputStream(path);
|
try {
|
||||||
ZipOutputStream zos = new ZipOutputStream(os)) {
|
try (OutputStream os = Files.newOutputStream(path);
|
||||||
ZipEntry e = new ZipEntry("x");
|
ZipOutputStream zos = new ZipOutputStream(os)) {
|
||||||
zos.putNextEntry(e);
|
ZipEntry e = new ZipEntry("x");
|
||||||
zos.write((int) 'x');
|
zos.putNextEntry(e);
|
||||||
}
|
zos.write((int) 'x');
|
||||||
int len = (int) Files.size(path);
|
}
|
||||||
byte[] data = new byte[len];
|
int len = (int) Files.size(path);
|
||||||
try (InputStream is = Files.newInputStream(path)) {
|
byte[] data = new byte[len];
|
||||||
is.read(data);
|
try (InputStream is = Files.newInputStream(path)) {
|
||||||
}
|
is.read(data);
|
||||||
Files.delete(path);
|
}
|
||||||
|
|
||||||
// year, month, day are zero
|
// year, month, day are zero
|
||||||
testDate(data.clone(), 0, LocalDate.of(1979, 11, 30).atStartOfDay());
|
testDate(data.clone(), 0, LocalDate.of(1979, 11, 30).atStartOfDay());
|
||||||
// only year is zero
|
// only year is zero
|
||||||
testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5).atStartOfDay());
|
testDate(data.clone(), 0 << 25 | 4 << 21 | 5 << 16, LocalDate.of(1980, 4, 5).atStartOfDay());
|
||||||
// month is greater than 12
|
// month is greater than 12
|
||||||
testDate(data.clone(), 0 << 25 | 13 << 21 | 1 << 16, LocalDate.of(1981, 1, 1).atStartOfDay());
|
testDate(data.clone(), 0 << 25 | 13 << 21 | 1 << 16, LocalDate.of(1981, 1, 1).atStartOfDay());
|
||||||
// 30th of February
|
// 30th of February
|
||||||
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16, LocalDate.of(1980, 3, 1).atStartOfDay());
|
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16, LocalDate.of(1980, 3, 1).atStartOfDay());
|
||||||
// 30th of February, 24:60:60
|
// 30th of February, 24:60:60
|
||||||
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16 | 24 << 11 | 60 << 5 | 60 >> 1,
|
testDate(data.clone(), 0 << 25 | 2 << 21 | 30 << 16 | 24 << 11 | 60 << 5 | 60 >> 1,
|
||||||
LocalDateTime.of(1980, 3, 2, 1, 1, 0));
|
LocalDateTime.of(1980, 3, 2, 1, 1, 0));
|
||||||
|
} finally {
|
||||||
|
Files.delete(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testDate(byte[] data, int date, LocalDateTime expected) throws IOException {
|
private static void testDate(byte[] data, int date, LocalDateTime expected) throws IOException {
|
||||||
@ -91,7 +97,7 @@ public class ZeroDate {
|
|||||||
writeU32(data, locpos + LOCTIM, date);
|
writeU32(data, locpos + LOCTIM, date);
|
||||||
|
|
||||||
// ensure that the archive is still readable, and the date is 1979-11-30
|
// ensure that the archive is still readable, and the date is 1979-11-30
|
||||||
Path path = Files.createTempFile("out", ".zip");
|
Path path = Utils.createTempFile("out", ".zip");
|
||||||
try (OutputStream os = Files.newOutputStream(path)) {
|
try (OutputStream os = Files.newOutputStream(path)) {
|
||||||
os.write(data);
|
os.write(data);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -33,6 +33,7 @@
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -66,24 +67,29 @@ public class P12SecretKey {
|
|||||||
ks.setEntry(ALIAS, ske, kspp);
|
ks.setEntry(ALIAS, ske, kspp);
|
||||||
|
|
||||||
File ksFile = File.createTempFile("test", ".test");
|
File ksFile = File.createTempFile("test", ".test");
|
||||||
try (FileOutputStream fos = new FileOutputStream(ksFile)) {
|
|
||||||
ks.store(fos, pw);
|
|
||||||
fos.flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
// now see if we can get it back
|
try {
|
||||||
try (FileInputStream fis = new FileInputStream(ksFile)) {
|
try (FileOutputStream fos = new FileOutputStream(ksFile)) {
|
||||||
KeyStore ks2 = KeyStore.getInstance(keystoreType);
|
ks.store(fos, pw);
|
||||||
ks2.load(fis, pw);
|
fos.flush();
|
||||||
KeyStore.Entry entry = ks2.getEntry(ALIAS, kspp);
|
|
||||||
SecretKey keyIn = ((KeyStore.SecretKeyEntry)entry).getSecretKey();
|
|
||||||
if (Arrays.equals(key.getEncoded(), keyIn.getEncoded())) {
|
|
||||||
System.err.println("OK: worked just fine with " + keystoreType +
|
|
||||||
" keystore");
|
|
||||||
} else {
|
|
||||||
System.err.println("ERROR: keys are NOT equal after storing in "
|
|
||||||
+ keystoreType + " keystore");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// now see if we can get it back
|
||||||
|
try (FileInputStream fis = new FileInputStream(ksFile)) {
|
||||||
|
KeyStore ks2 = KeyStore.getInstance(keystoreType);
|
||||||
|
ks2.load(fis, pw);
|
||||||
|
KeyStore.Entry entry = ks2.getEntry(ALIAS, kspp);
|
||||||
|
SecretKey keyIn = ((KeyStore.SecretKeyEntry) entry).getSecretKey();
|
||||||
|
if (Arrays.equals(key.getEncoded(), keyIn.getEncoded())) {
|
||||||
|
System.err.println("OK: worked just fine with " + keystoreType +
|
||||||
|
" keystore");
|
||||||
|
} else {
|
||||||
|
System.err.println("ERROR: keys are NOT equal after storing in "
|
||||||
|
+ keystoreType + " keystore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Files.deleteIfExists(ksFile.toPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user