# HG changeset patch # User attila # Date 1409058288 -7200 # Node ID 5fbbd38ebc5b38f94cbb272c0f3d1db9988aee34 # Parent 9e9455565f77c267018ceeaf74a23bd4abaf57e4 8056052: Source.getContent() does excess Object.clone() Reviewed-by: jlaskey, sundar diff -r 9e9455565f77 -r 5fbbd38ebc5b nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Tue Aug 26 15:04:20 2014 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Tue Aug 26 15:04:48 2014 +0200 @@ -711,11 +711,16 @@ } /** - * Get the content of this source as a char array - * @return content + * Get the content of this source as a char array. Note that the underlying array is returned instead of a + * clone; modifying the char array will cause modification to the source; this should not be done. While + * there is an apparent danger that we allow unfettered access to an underlying mutable array, the + * {@code Source} class is in a restricted {@code jdk.nashorn.internal.*} package and as such it is + * inaccessible by external actors in an environment with a security manager. Returning a clone would be + * detrimental to performance. + * @return content the content of this source as a char array */ public char[] getContent() { - return data().clone(); + return data(); } /** diff -r 9e9455565f77 -r 5fbbd38ebc5b nashorn/test/src/jdk/nashorn/internal/runtime/SourceTest.java --- a/nashorn/test/src/jdk/nashorn/internal/runtime/SourceTest.java Tue Aug 26 15:04:20 2014 +0200 +++ b/nashorn/test/src/jdk/nashorn/internal/runtime/SourceTest.java Tue Aug 26 15:04:48 2014 +0200 @@ -117,9 +117,6 @@ assertEquals(str1, str2); assertEquals(source1.hashCode(), source2.hashCode()); assertTrue(source1.equals(source2)); - // Test for immutability - Arrays.fill(source1.getContent(), (char)0); - Arrays.fill(source2.getContent(), (char)1); assertTrue(Arrays.equals(source1.getContent(), str1.toCharArray())); assertTrue(Arrays.equals(source1.getContent(), chars1)); assertTrue(Arrays.equals(source1.getContent(), source2.getContent()));