Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8209736: runtime/RedefineTests/ModifyAnonymous.java fails with NullPointerException when running in CDS mode #1134

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,9 @@
* @run main/othervm -javaagent:redefineagent.jar ModifyAnonymous
*/

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.lang.RuntimeException;
import java.lang.instrument.ClassDefinition;
@@ -107,12 +109,39 @@ public void doWork() {
}

static void runTest() {
PrintWriter pw;
String logName = System.getProperty("test.classes") +
File.separator + "loadedClasses.log";
// Create a log file to capture the names of the classes in the
// allLoadedClasses array. The log file is for assisting in debugging
// in case a null class is encountered in the allLoadedClasses array.
try {
pw = new PrintWriter(new FileOutputStream(
new File(logName), true));
} catch (FileNotFoundException e) {
throw new RuntimeException("Could not write loaded classes to log", e);
}
while (!done) {
Class[] allLoadedClasses = inst.getAllLoadedClasses();
for (Class clazz : allLoadedClasses) {
int len = allLoadedClasses.length;
pw.println(" allLoadedClasses length: " + len);
for (int idx = 0; idx < len; idx++) {
Class cls = allLoadedClasses[idx];
pw.println(" " + idx + " " +
((cls != null) ? cls.getName() : "null"));
}
for (int idx = 0; idx < len; idx++) {
Class clazz = allLoadedClasses[idx];
if (clazz == null) {
pw.flush();
pw.close();
throw new RuntimeException("null class encountered");
}
final String name = clazz.getName();
if (name.contains("$$Lambda$") && name.contains("App")) {
if (inst.isModifiableClass(clazz)) {
pw.flush();
pw.close();
throw new RuntimeException ("Class should not be modifiable");
}
// Try to modify them anyway.
@@ -133,12 +162,16 @@ static void runTest() {
System.out.println("PASSED: expecting UnmodifiableClassException");
t.printStackTrace();
} catch(java.lang.ClassNotFoundException e) {
pw.flush();
pw.close();
throw new RuntimeException ("ClassNotFoundException thrown");
}
done = true;
}
}
}
pw.flush();
pw.close();
}

public static void main(String argv[]) throws InterruptedException, RuntimeException {