--- a/jdk/src/share/classes/java/lang/reflect/Modifier.java Tue Aug 05 10:01:38 2014 -0400
+++ b/jdk/src/share/classes/java/lang/reflect/Modifier.java Wed Aug 06 02:11:17 2014 +0400
@@ -26,6 +26,7 @@
package java.lang.reflect;
import java.security.AccessController;
+import java.util.StringJoiner;
import sun.reflect.LangReflectAccess;
import sun.reflect.ReflectionFactory;
@@ -232,27 +233,24 @@
* represented by {@code mod}
*/
public static String toString(int mod) {
- StringBuilder sb = new StringBuilder();
- int len;
+ StringJoiner sj = new StringJoiner(" ");
- if ((mod & PUBLIC) != 0) sb.append("public ");
- if ((mod & PROTECTED) != 0) sb.append("protected ");
- if ((mod & PRIVATE) != 0) sb.append("private ");
+ if ((mod & PUBLIC) != 0) sj.add("public");
+ if ((mod & PROTECTED) != 0) sj.add("protected");
+ if ((mod & PRIVATE) != 0) sj.add("private");
/* Canonical order */
- if ((mod & ABSTRACT) != 0) sb.append("abstract ");
- if ((mod & STATIC) != 0) sb.append("static ");
- if ((mod & FINAL) != 0) sb.append("final ");
- if ((mod & TRANSIENT) != 0) sb.append("transient ");
- if ((mod & VOLATILE) != 0) sb.append("volatile ");
- if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
- if ((mod & NATIVE) != 0) sb.append("native ");
- if ((mod & STRICT) != 0) sb.append("strictfp ");
- if ((mod & INTERFACE) != 0) sb.append("interface ");
+ if ((mod & ABSTRACT) != 0) sj.add("abstract");
+ if ((mod & STATIC) != 0) sj.add("static");
+ if ((mod & FINAL) != 0) sj.add("final");
+ if ((mod & TRANSIENT) != 0) sj.add("transient");
+ if ((mod & VOLATILE) != 0) sj.add("volatile");
+ if ((mod & SYNCHRONIZED) != 0) sj.add("synchronized");
+ if ((mod & NATIVE) != 0) sj.add("native");
+ if ((mod & STRICT) != 0) sj.add("strictfp");
+ if ((mod & INTERFACE) != 0) sj.add("interface");
- if ((len = sb.length()) > 0) /* trim trailing space */
- return sb.toString().substring(0, len-1);
- return "";
+ return sj.toString();
}
/*
--- a/jdk/test/java/lang/reflect/Modifier/toStringTest.java Tue Aug 05 10:01:38 2014 -0400
+++ b/jdk/test/java/lang/reflect/Modifier/toStringTest.java Wed Aug 06 02:11:17 2014 +0400
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2014, 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
@@ -23,11 +23,11 @@
/**
* @test
- * @bug 4394937
+ * @bug 4394937 8051382
* @summary tests the toString method of reflect.Modifier
*/
-import java.lang.reflect.*;
+import java.lang.reflect.Modifier;
public class toStringTest {