Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import com.google.common.collect.Range;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.internal.InternalFutureFailureAccess;
import java.io.InputStream;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.MethodModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -87,6 +91,34 @@ public void testSuccess() throws ExecutionException, InterruptedException {
.isEqualTo(value);
}

@J2ktIncompatible
@AndroidIncompatible
@SuppressWarnings({
"Java8ApiChecker", // We check isJava8 before Runtime and Runtime before using ClassModel
"deprecation", // Version.feature() isn't available until 10, so we use major() to support 9
})
public void testAssertNoClinit() throws Exception {
if (isJava8() || Runtime.version().major() < 24) {
return;
}

String abstractFuturePath = AbstractFuture.class.getName().replace('.', '/') + ".class";

try (InputStream stream =
AbstractFuture.class.getClassLoader().getResourceAsStream(abstractFuturePath)) {
ClassModel classModel = ClassFile.of().parse(stream.readAllBytes());

for (MethodModel method : classModel.methods()) {
if (method.methodName().stringValue().equals("<clinit>")) {
assertWithMessage(
"AbstractFuture should not have a static initializer (<clinit>) "
+ "to prevent potential class-loading deadlocks.")
.fail();
}
}
}
}

@J2ktIncompatible // J2KT ExecutionException differs in stack trace
public void testException() throws InterruptedException {
Throwable failure = new Throwable();
Expand Down Expand Up @@ -814,7 +846,6 @@ public void testSetFuture_stackOverflow() {
// Verify that StackOverflowError in a long chain of SetFuture doesn't cause the entire toString
// call to fail
@J2ktIncompatible
@GwtIncompatible
@AndroidIncompatible // b/391667564: crashes from stack overflows
public void testSetFutureToString_stackOverflow() {
SettableFuture<String> orig = SettableFuture.create();
Expand Down Expand Up @@ -1290,4 +1321,8 @@ protected void interruptTask() {
private static boolean isWindows() {
return OS_NAME.value().startsWith("Windows");
}

private static boolean isJava8() {
return JAVA_SPECIFICATION_VERSION.value().equals("1.8");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
import com.google.common.collect.Range;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.internal.InternalFutureFailureAccess;
import java.io.InputStream;
import java.lang.classfile.ClassFile;
import java.lang.classfile.ClassModel;
import java.lang.classfile.MethodModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -87,6 +91,34 @@ public void testSuccess() throws ExecutionException, InterruptedException {
.isEqualTo(value);
}

@J2ktIncompatible
@AndroidIncompatible
@SuppressWarnings({
"Java8ApiChecker", // We check isJava8 before Runtime and Runtime before using ClassModel
"deprecation", // Version.feature() isn't available until 10, so we use major() to support 9
})
public void testAssertNoClinit() throws Exception {
if (isJava8() || Runtime.version().major() < 24) {
return;
}

String abstractFuturePath = AbstractFuture.class.getName().replace('.', '/') + ".class";

try (InputStream stream =
AbstractFuture.class.getClassLoader().getResourceAsStream(abstractFuturePath)) {
ClassModel classModel = ClassFile.of().parse(stream.readAllBytes());

for (MethodModel method : classModel.methods()) {
if (method.methodName().stringValue().equals("<clinit>")) {
assertWithMessage(
"AbstractFuture should not have a static initializer (<clinit>) "
+ "to prevent potential class-loading deadlocks.")
.fail();
}
}
}
}

@J2ktIncompatible // J2KT ExecutionException differs in stack trace
public void testException() throws InterruptedException {
Throwable failure = new Throwable();
Expand Down Expand Up @@ -814,7 +846,6 @@ public void testSetFuture_stackOverflow() {
// Verify that StackOverflowError in a long chain of SetFuture doesn't cause the entire toString
// call to fail
@J2ktIncompatible
@GwtIncompatible
@AndroidIncompatible // b/391667564: crashes from stack overflows
public void testSetFutureToString_stackOverflow() {
SettableFuture<String> orig = SettableFuture.create();
Expand Down Expand Up @@ -1290,4 +1321,8 @@ protected void interruptTask() {
private static boolean isWindows() {
return OS_NAME.value().startsWith("Windows");
}

private static boolean isJava8() {
return JAVA_SPECIFICATION_VERSION.value().equals("1.8");
}
}
Loading