Mercurial > people > rkennke > jdk9-shenandoah-final > nashorn
changeset 991:46af7f9765dc
8056052: Source.getContent() does excess Object.clone()
Reviewed-by: jlaskey, sundar
author | attila |
---|---|
date | Tue, 26 Aug 2014 15:04:48 +0200 |
parents | fda747208c6f |
children | fa79d912da1b |
files | src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java test/src/jdk/nashorn/internal/runtime/SourceTest.java |
diffstat | 2 files changed, 8 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java Tue Aug 26 15:04:20 2014 +0200 +++ b/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(); } /**
--- a/test/src/jdk/nashorn/internal/runtime/SourceTest.java Tue Aug 26 15:04:20 2014 +0200 +++ b/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()));