--- old/src/java.base/share/classes/java/lang/String.java 2018-03-01 18:43:32.304131469 -0800 +++ new/src/java.base/share/classes/java/lang/String.java 2018-03-01 18:43:32.023126314 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 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 @@ -3108,4 +3108,25 @@ "begin " + begin + ", end " + end + ", length " + length); } } + + /** + * Returns the string representation of the {@code codePoint} + * argument. + * + * @param codepoint a {@code codePoint}. + * @return a string of length {@code 1} or {@code 2} containing + * as its single character the argument {@code codePoint}. + * @throws IllegalArgumentException if the specified + * {@code codePoint} is not a {@linkplain Character#isValidCodePoint + * valid Unicode code point}. + */ + static String valueOfCodePoint(int cp) { + if (COMPACT_STRINGS && StringLatin1.canEncode(cp)) { + return new String(StringLatin1.toBytes((char)cp), LATIN1); + } else if (Character.isValidCodePoint(cp)) { + return new String(StringUTF16.toBytes(cp), UTF16); + } else { + throw new IllegalArgumentException(); + } + } }