Skip to content

8358813: remove more bindings for JPasswordFields in Aqua #25688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ LateBoundInputMap getPasswordFieldInputMap() {
"shift alt KP_LEFT", null,
"shift alt RIGHT", null,
"shift alt KP_RIGHT", null,
"alt BACK_SPACE", null,
"ctrl W", null,
"alt DELETE", null
}));
}

Expand Down
107 changes: 107 additions & 0 deletions test/jdk/javax/swing/JPasswordField/PasswordFieldInputMapWordTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/**
* @test
* @key headful
* @bug 8358813
* @summary Password fields' InputMap should not include any word-related action.
*
* @run main PasswordFieldInputMapWordTest
*/

import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JPasswordField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.text.DefaultEditorKit;

public class PasswordFieldInputMapWordTest {
public static void main(String[] args) throws Exception {
for (UIManager.LookAndFeelInfo laf :
UIManager.getInstalledLookAndFeels()) {
System.out.println("Testing LAF: " + laf.getClassName());
SwingUtilities.invokeAndWait(() -> {
if (setLookAndFeel(laf)) {
runTest();
}
});
}
}

private static boolean setLookAndFeel(UIManager.LookAndFeelInfo laf) {
try {
UIManager.setLookAndFeel(laf.getClassName());
return true;
} catch (UnsupportedLookAndFeelException e) {
System.err.println("Skipping unsupported look and feel:");
e.printStackTrace();
return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private static void runTest() {
JPasswordField field = new JPasswordField();

boolean testPassed = true;
for (int condition : new int[] {
JComponent.WHEN_IN_FOCUSED_WINDOW,
JComponent.WHEN_FOCUSED,
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
}) {
InputMap inputMap = field.getInputMap(condition);
if (inputMap.allKeys() == null) {
continue;
}
for (KeyStroke keyStroke : inputMap.allKeys()) {
Object actionBinding = inputMap.get(keyStroke);
// these are all the actions with "word" in the name:
if (actionBinding == DefaultEditorKit.deleteNextWordAction ||
actionBinding == DefaultEditorKit.deletePrevWordAction ||
actionBinding == DefaultEditorKit.beginWordAction ||
actionBinding == DefaultEditorKit.endWordAction ||
actionBinding == DefaultEditorKit.selectionBeginWordAction ||
actionBinding == DefaultEditorKit.selectionEndWordAction ||
actionBinding == DefaultEditorKit.previousWordAction ||
actionBinding == DefaultEditorKit.nextWordAction ||
actionBinding == DefaultEditorKit.selectionPreviousWordAction ||
actionBinding == DefaultEditorKit.selectionNextWordAction ) {
if (testPassed) {
System.err.println("The following inputs/actions should not be available in a JPasswordField:");
}
System.err.println(inputMap.get(keyStroke) + " (try typing " + keyStroke + ")");
testPassed = false;
}
}
}

if (!testPassed) {
throw new RuntimeException("One or more input/action binding was observed for a JPasswordField.");
}
}
}