提交 709dd180 编写于 作者: M mchung

6924497: HotSpotDiagnosticsMXBean.getDiagnosticOptions throws NPE

Summary: Check if the element in the flags array is non-null to filter unsupported flags
Reviewed-by: dcubed
上级 6c9941d5
......@@ -68,27 +68,42 @@ class Flag {
}
static Flag getFlag(String name) {
Flag[] fs = new Flag[1];
String[] names = new String[1];
names[0] = name;
int count = getFlags(names, fs, 1);
if (count == 1) {
return fs[0];
} else {
List<Flag> flags = getFlags(names, 1);
if (flags.isEmpty()) {
return null;
} else {
// flags should have only one element
return flags.get(0);
}
}
static List<Flag> getAllFlags() {
int numFlags = getInternalFlagCount();
Flag[] fs = new Flag[numFlags];
// Get all internal flags with names = null
int count = getFlags(null, fs, numFlags);
return Arrays.asList(fs);
return getFlags(null, numFlags);
}
private static List<Flag> getFlags(String[] names, int numFlags) {
Flag[] flags = new Flag[numFlags];
int count = getFlags(names, flags, numFlags);
List<Flag> result = new ArrayList<Flag>();
for (Flag f : flags) {
if (f != null) {
result.add(f);
}
}
return result;
}
private static native String[] getAllFlagNames();
// getFlags sets each element in the given flags array
// with a Flag object only if the name is valid and the
// type is supported. The flags array may contain null elements.
private static native int getFlags(String[] names, Flag[] flags, int count);
private static native int getInternalFlagCount();
......
......@@ -84,6 +84,7 @@ Java_sun_management_Flag_getFlags
jint num_flags, i, index;
jmmVMGlobal* globals;
size_t gsize;
const char* class_name = "sun/management/Flag";
const char* signature = "(Ljava/lang/String;Ljava/lang/Object;ZZLcom/sun/management/VMOption$Origin;)V";
jobject origin;
......@@ -100,12 +101,14 @@ Java_sun_management_Flag_getFlags
return 0;
}
globals = (jmmVMGlobal*) malloc(count * sizeof(jmmVMGlobal));
gsize = count * sizeof(jmmVMGlobal);
globals = (jmmVMGlobal*) malloc(gsize);
if (globals == NULL) {
JNU_ThrowOutOfMemoryError(env, 0);
return 0;
}
memset(globals, 0, gsize);
num_flags = jmm_interface->GetVMGlobals(env, names, globals, count);
if (num_flags == 0) {
free(globals);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册