8173123: [findbugs] javax.swing.text.* - Storing a reference to an externally mutable object into the internal representation
authorpsadhukhan
Tue, 14 Mar 2017 10:29:13 +0530
changeset 44343 f0c8e3d65331
parent 44342 e8285d724740
child 44344 e06a7379b9c7
8173123: [findbugs] javax.swing.text.* - Storing a reference to an externally mutable object into the internal representation Reviewed-by: serb, alexsch, prr
jdk/src/java.desktop/share/classes/javax/swing/text/DefaultStyledDocument.java
jdk/src/java.desktop/share/classes/javax/swing/text/StyleContext.java
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/DefaultStyledDocument.java	Mon Mar 13 22:55:10 2017 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/swing/text/DefaultStyledDocument.java	Tue Mar 14 10:29:13 2017 +0530
@@ -39,6 +39,7 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.Serializable;
+import java.util.Arrays;
 import javax.swing.event.*;
 import javax.swing.undo.AbstractUndoableEdit;
 import javax.swing.undo.CannotRedoException;
@@ -1263,7 +1264,7 @@
                                   int offs, int len) {
             attr = a;
             this.type = type;
-            this.data = txt;
+            this.data = txt == null ? null : Arrays.copyOf(txt, txt.length);
             this.offs = offs;
             this.len = len;
             this.direction = OriginateDirection;
@@ -1323,7 +1324,7 @@
          * @return the array
          */
         public char[] getArray() {
-            return data;
+            return data == null ? null : Arrays.copyOf(data, data.length);
         }
 
 
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/StyleContext.java	Mon Mar 13 22:55:10 2017 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/swing/text/StyleContext.java	Tue Mar 14 10:29:13 2017 +0530
@@ -794,7 +794,7 @@
          * @param attributes the attributes
          */
         public SmallAttributeSet(Object[] attributes) {
-            this.attributes = attributes;
+            this.attributes = Arrays.copyOf(attributes, attributes.length);
             updateResolveParent();
         }