Skip to content

Commit

Permalink
8338603: DiagnosticCommandMBean operations should standardize types f…
Browse files Browse the repository at this point in the history
…or parameters

Reviewed-by: cjplummer, egahlin
  • Loading branch information
kevinjwalls committed Oct 15, 2024
1 parent c9a536c commit df7d6e0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, 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.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -317,7 +317,7 @@ private Descriptor commandDescriptor(Wrapper w) throws IllegalArgumentException
for (DiagnosticCommandArgumentInfo arginfo : w.info.getArgumentsInfo()) {
HashMap<String, Object> argmap = new HashMap<>();
argmap.put("dcmd.arg.name", arginfo.getName());
argmap.put("dcmd.arg.type", arginfo.getType());
argmap.put("dcmd.arg.type", sanitiseType(arginfo.getType()));
argmap.put("dcmd.arg.description", arginfo.getDescription());
argmap.put("dcmd.arg.isMandatory", arginfo.isMandatory());
argmap.put("dcmd.arg.isMultiple", arginfo.isMultiple());
Expand All @@ -335,6 +335,22 @@ private Descriptor commandDescriptor(Wrapper w) throws IllegalArgumentException
return new ImmutableDescriptor(map);
}

// Type names that will be published in dcmd.arg.type:
private static final String [] publicTypes = new String [] { "INT", "STRING", "BOOLEAN", "STRING SET", "MEMORY SIZE", "NANOTIME" };

private static final String sanitiseType(String typeName) {
// For any typeName not in the set to be made public, return "STRING".
if (typeName == null) {
return null;
}
for (String t : publicTypes) {
if (typeName.equals(t)) {
return t;
}
}
return "STRING";
}

private static final String notifName =
"javax.management.Notification";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2015, 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.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,7 +23,7 @@

/*
* @test
* @bug 7150256
* @bug 7150256 8338603
* @summary Basic Test for the DiagnosticCommandMBean
* @author Frederic Parain, Shanliang JIANG
*
Expand Down Expand Up @@ -68,10 +68,14 @@ public static void main(String[] args) throws Exception {
System.out.println("Description:" + info.getDescription());
MBeanOperationInfo[] opInfo = info.getOperations();
System.out.println("Operations:");
int operationFailures = 0;
for (int i = 0; i < opInfo.length; i++) {
printOperation(opInfo[i]);
operationFailures += printOperation(opInfo[i]);
System.out.println("\n@@@@@@\n");
}
if (operationFailures > 0) {
throw new RuntimeException("FAILED. " + operationFailures + " operations found with non-standard parameter types.");
}
} finally {
try {
cc.close();
Expand All @@ -83,7 +87,12 @@ public static void main(String[] args) throws Exception {
System.out.println("Test passed");
}

static void printOperation(MBeanOperationInfo info) {
/**
* Print an Operation, and check for any non-standard parameter types.
* Return the number of failed parameters, so the caller can signal to fail the test.
*/
static int printOperation(MBeanOperationInfo info) {
int failures = 0;
System.out.println("Name: "+info.getName());
System.out.println("Description: "+info.getDescription());
System.out.println("Return Type: "+info.getReturnType());
Expand All @@ -100,14 +109,39 @@ static void printOperation(MBeanOperationInfo info) {
Descriptor desc3 =
(Descriptor)desc2.getFieldValue(desc2.getFieldNames()[j]);
for(int k=0; k<desc3.getFieldNames().length; k++) {
System.out.println("\t\t\t"+desc3.getFieldNames()[k]+"="
+desc3.getFieldValue(desc3.getFieldNames()[k]));
String fieldName3 = desc3.getFieldNames()[k];
Object fieldValue3 = desc3.getFieldValue(fieldName3);
System.out.print("\t\t\t" + fieldName3 + "=" + fieldValue3);
if (fieldName3.equals("dcmd.arg.type")) {
if (!isPublicType((String) fieldValue3)) {
System.out.print("\t** FAILED ** not a standard type");
failures++;
}
}
System.out.println();
}
}
} else {
System.out.println("\t"+desc.getFieldNames()[i]+"="
+desc.getFieldValue(desc.getFieldNames()[i]));
}
}
return failures;
}

// Knowledge of the implementation-dependent types in DiagnosticCommandImpl, seen by applications/users
// (see the DiagnosticCommandMBean Descriptor, field "dcmd.arg.type").
private static final String [] publicTypes = new String [] { "INT", "STRING", "BOOLEAN", "STRING SET", "MEMORY SIZE", "NANOTIME" };

private static final boolean isPublicType(String typeName) {
if (typeName == null) {
return false;
}
for (String t : publicTypes) {
if (typeName.equals(t)) {
return true;
}
}
return false;
}
}

1 comment on commit df7d6e0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.