8173123: [findbugs] javax.swing.text.* - Storing a reference to an externally mutable object into the internal representation
Reviewed-by: serb, alexsch, prr
--- 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();
}