Index: modules/luni/src/main/java/java/lang/String.java =================================================================== --- modules/luni/src/main/java/java/lang/String.java.orig 2006-05-22 16:00:37.000000000 +0100 +++ modules/luni/src/main/java/java/lang/String.java 2006-05-22 16:01:42.000000000 +0100 @@ -344,8 +344,12 @@ offset = 0; Charset charset; try { - charset = Charset.forName(encoding); - } catch (UnsupportedCharsetException e) { + try { + charset = Charset.forName(encoding); + } catch (UnsupportedCharsetException e) { + throw new UnsupportedEncodingException(); + } + } catch (IllegalCharsetNameException e) { throw new UnsupportedEncodingException(); } int result; @@ -835,8 +839,20 @@ * @see UnsupportedEncodingException */ public byte[] getBytes(String encoding) throws UnsupportedEncodingException { - ByteBuffer buffer = getCharset(encoding).encode( - CharBuffer.wrap(this.value, this.offset, this.count)); + + ByteBuffer buffer; + try { + try { + buffer = getCharset(encoding).encode( + CharBuffer.wrap(this.value, + this.offset, + this.count)); + } catch (UnsupportedCharsetException e) { + throw new UnsupportedEncodingException(); + } + } catch (IllegalCharsetNameException e) { + throw new UnsupportedEncodingException(); + } byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; Index: modules/luni/src/test/java/tests/api/java/lang/StringTest.java =================================================================== --- modules/luni/src/test/java/tests/api/java/lang/StringTest.java.orig 2006-05-22 16:00:37.000000000 +0100 +++ modules/luni/src/test/java/tests/api/java/lang/StringTest.java 2006-05-22 16:00:50.000000000 +0100 @@ -891,6 +891,31 @@ && (String.valueOf(true).equals("true"))); } + /** + * @tests java.lang.String#String(byte[], java.lang.String) + */ + public void test_constructor_exception() { + // REGRESSION for HARMONY-487 + try { + byte b[] = {}; + String s = new String(b, ""); + } catch (UnsupportedEncodingException e) { + // expected + } + } + + /** + * @tests java.lang.String#getBytes(String) + */ + public void test_getBytes_exception() { + // REGRESSION for HARMONY-487 + try { + (new String()).getBytes(""); + } catch (UnsupportedEncodingException e) { + // expected + } + } + /** * Sets up the fixture, for example, open a network connection. This method * is called before a test is executed.