--- a/jdk/src/share/classes/sun/management/Flag.java Sat Feb 06 09:26:57 2010 -0800
+++ b/jdk/src/share/classes/sun/management/Flag.java Mon Feb 08 23:02:28 2010 -0800
@@ -68,27 +68,42 @@
}
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];
+
+ List<Flag> flags = getFlags(names, 1);
+ if (flags.isEmpty()) {
+ return null;
} else {
- return null;
+ // 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();