-
Bug
-
Resolution: Fixed
-
P3
-
8u291, 11.0.11, 17, 19, 20
-
b01
-
b26
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8326976 | 17.0.12-oracle | Alexey Ivanov | P3 | Resolved | Fixed | b01 |
JDK-8298534 | 17.0.7 | Sergey Bylokhov | P3 | Resolved | Fixed | b01 |
JDK-8326977 | 11.0.24-oracle | Alexey Ivanov | P3 | Resolved | Fixed | b01 |
JDK-8298537 | 11.0.19 | Sergey Bylokhov | P3 | Resolved | Fixed | b01 |
To clear a JPasswordField you're supposed to do setText(""). In versions before 11.0.11 this would work if that field had a document filter attached to it, but since 11.0.11 this does not work anymore, and instead the currently inserted characters will be replaced with unicode null characters instead.
Visually and functionally this means the passwordfield is not empty.
Tested versions:
11.0.11+9 (does no work)
11.0.10+9 (does work)
REGRESSION : Last worked in version 11.0.10
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a JPasswordField
2. Get the document as PlainDocument from the field
3. Set a documentFilter
4. Input text in the JPasswordField (either through the UI or with setTexT(String)
5. Clear the text with setText("") (ie. with a button)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The field is empty
ACTUAL -
The originally set characters get replaced with unicode null characters
---------- BEGIN SOURCE ----------
public class PasswordTest {
public static void main(String... args) {
JPasswordField test = new JPasswordField();
PlainDocument document = (PlainDocument) test.getDocument();
document.setDocumentFilter(new DocumentFilter() {
@Override
public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
String string = fb.getDocument().getText(0, fb.getDocument().getLength()) + text;
if (string.length() <= 6 && string.matches("[0-9]+")) {
super.replace(fb, offset, length, text, attrs); //To change body of generated methods, choose Tools | Templates.
}
}
});
test.setText("123456");
test.setText("");
System.out.println(Arrays.equals(test.getPassword(), new char[0]));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Remove the document filter.
FREQUENCY : always
- backported by
-
JDK-8298534 Document Filter attached to JPasswordField and setText("") is not cleared instead inserted characters replaced with unicode null characters
- Resolved
-
JDK-8298537 Document Filter attached to JPasswordField and setText("") is not cleared instead inserted characters replaced with unicode null characters
- Resolved
-
JDK-8326976 Document Filter attached to JPasswordField and setText("") is not cleared instead inserted characters replaced with unicode null characters
- Resolved
-
JDK-8326977 Document Filter attached to JPasswordField and setText("") is not cleared instead inserted characters replaced with unicode null characters
- Resolved
- relates to
-
JDK-8258373 Update the text handling in the JPasswordField
- Resolved
- links to
-
Commit openjdk/jdk11u-dev/9197181f
-
Commit openjdk/jdk17u-dev/55159831
-
Commit openjdk/jdk/87f00f4a
-
Review openjdk/jdk11u-dev/1563
-
Review openjdk/jdk17u-dev/943
-
Review openjdk/jdk19u/102
-
Review openjdk/jdk/11281