Index: trunk/src/org/openstreetmap/josm/gui/MainApplet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainApplet.java	(revision 5751)
+++ trunk/src/org/openstreetmap/josm/gui/MainApplet.java	(revision 5752)
@@ -29,4 +29,5 @@
 import org.openstreetmap.josm.data.ServerSidePreferences;
 import org.openstreetmap.josm.gui.MainApplication.Option;
+import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.I18n;
@@ -113,5 +114,5 @@
                 p.add(user, GBC.eol().fill(GBC.HORIZONTAL));
                 p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0));
-                JPasswordField pass = new JPasswordField(password == null ? "" : password);
+                JPasswordField pass = new JosmPasswordField(password == null ? "" : password);
                 p.add(pass, GBC.eol().fill(GBC.HORIZONTAL));
                 JOptionPane.showMessageDialog(null, p);
Index: trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java	(revision 5751)
+++ trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java	(revision 5752)
@@ -36,4 +36,5 @@
 import org.openstreetmap.josm.gui.help.HelpUtil;
 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
+import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
 import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.tools.ImageProvider;
@@ -157,5 +158,5 @@
         protected void build() {
             tfUserName = new JTextField(20);
-            tfPassword = new JPasswordField(20);
+            tfPassword = new JosmPasswordField(20);
             tfUserName.addFocusListener(new SelectAllOnFocusHandler());
             tfPassword.addFocusListener(new SelectAllOnFocusHandler());
Index: trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java	(revision 5751)
+++ trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticAuthorizationUI.java	(revision 5752)
@@ -40,4 +40,5 @@
 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
 import org.openstreetmap.josm.gui.widgets.HtmlPanel;
+import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
@@ -130,5 +131,5 @@
         gc.gridx = 1;
         gc.weightx = 1.0;
-        pnl.add(tfPassword = new JPasswordField(), gc);
+        pnl.add(tfPassword = new JosmPasswordField(), gc);
         SelectAllOnFocusGainedDecorator.decorate(tfPassword);
         valPassword = new PasswordValidator(tfPassword);
Index: trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticPropertiesPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticPropertiesPanel.java	(revision 5751)
+++ trunk/src/org/openstreetmap/josm/gui/oauth/FullyAutomaticPropertiesPanel.java	(revision 5752)
@@ -17,4 +17,5 @@
 
 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
+import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
 
@@ -56,5 +57,5 @@
         gc.gridx = 1;
         gc.weightx = 1.0;
-        pnl.add(tfPassword = new JPasswordField(), gc);
+        pnl.add(tfPassword = new JosmPasswordField(), gc);
         SelectAllOnFocusGainedDecorator.decorate(tfPassword);
 
Index: trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java	(revision 5751)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/server/BasicAuthenticationPreferencesPanel.java	(revision 5752)
@@ -17,10 +17,9 @@
 import javax.swing.JTextField;
 
-import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
 import org.openstreetmap.josm.io.auth.CredentialsAgent;
 import org.openstreetmap.josm.io.auth.CredentialsAgentException;
 import org.openstreetmap.josm.io.auth.CredentialsManager;
-import org.openstreetmap.josm.io.auth.JosmPreferencesCredentialAgent;
 import org.openstreetmap.josm.io.OsmApi;
 
@@ -70,5 +69,5 @@
         gc.gridx = 1;
         gc.weightx = 1.0;
-        add(tfOsmPassword = new JPasswordField(), gc);
+        add(tfOsmPassword = new JosmPasswordField(), gc);
         SelectAllOnFocusGainedDecorator.decorate(tfOsmPassword);
         tfOsmPassword.setToolTipText(tr("Please enter your OSM password"));
Index: trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java	(revision 5751)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java	(revision 5752)
@@ -29,4 +29,5 @@
 import org.openstreetmap.josm.gui.JMultilineLabel;
 import org.openstreetmap.josm.gui.help.HelpUtil;
+import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
 import org.openstreetmap.josm.io.DefaultProxySelector;
@@ -146,5 +147,5 @@
         gc.gridx = 1;
         gc.weightx = 1.0;
-        pnl.add(tfProxyHttpPassword = new JPasswordField(20),gc);
+        pnl.add(tfProxyHttpPassword = new JosmPasswordField(20),gc);
         tfProxyHttpPassword.setMinimumSize(tfProxyHttpPassword.getPreferredSize());
 
Index: trunk/src/org/openstreetmap/josm/gui/widgets/JosmPasswordField.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/widgets/JosmPasswordField.java	(revision 5752)
+++ trunk/src/org/openstreetmap/josm/gui/widgets/JosmPasswordField.java	(revision 5752)
@@ -0,0 +1,142 @@
+package org.openstreetmap.josm.gui.widgets;
+
+import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.Action;
+import javax.swing.JPasswordField;
+import javax.swing.TransferHandler;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+
+/**
+ * A subclass of {@link JPasswordField} to implement a workaround to 
+ * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6322854">JDK bug 6322854</a>.
+ * This class can be deleted after Oracle decides to fix this bug...
+ * 
+ * @since 5752
+ * @see <a href="http://josm.openstreetmap.de/ticket/8404">http://josm.openstreetmap.de/ticket/8404</a>
+ * @see <a href="http://hg.netbeans.org/main/rev/33cb2e81b640">http://hg.netbeans.org/main/rev/33cb2e81b640</a>
+ */
+public class JosmPasswordField extends JPasswordField {
+
+    /**
+     * Constructs a new <code>JosmPasswordField</code>,
+     * with a default document, <code>null</code> starting
+     * text string, and 0 column width.
+     */
+    public JosmPasswordField() {
+        workaroundJdkBug6322854(this);
+    }
+
+    /**
+     * Constructs a new <code>JosmPasswordField</code> that uses the
+     * given text storage model and the given number of columns. 
+     * This is the constructor through which the other constructors feed.
+     * The echo character is set to '*', but may be changed by the current
+     * Look and Feel.  If the document model is
+     * <code>null</code>, a default one will be created.
+     *
+     * @param doc  the text storage to use
+     * @param txt the text to be displayed, <code>null</code> if none
+     * @param columns  the number of columns to use to calculate 
+     *   the preferred width >= 0; if columns is set to zero, the
+     *   preferred width will be whatever naturally results from
+     *   the component implementation
+     */
+    public JosmPasswordField(Document doc, String txt, int columns) {
+        super(doc, txt, columns);
+        workaroundJdkBug6322854(this);
+    }
+
+    /**
+     * Constructs a new empty <code>JosmPasswordField</code> with the specified
+     * number of columns.  A default model is created, and the initial string
+     * is set to <code>null</code>.
+     *
+     * @param columns the number of columns >= 0
+     */ 
+    public JosmPasswordField(int columns) {
+        super(columns);
+        workaroundJdkBug6322854(this);
+    }
+
+    /**
+     * Constructs a new <code>JPasswordField</code> initialized with
+     * the specified text and columns.  The document model is set to
+     * the default.
+     *
+     * @param text the text to be displayed, <code>null</code> if none
+     * @param columns the number of columns >= 0
+     */
+    public JosmPasswordField(String text, int columns) {
+        super(text, columns);
+        workaroundJdkBug6322854(this);
+    }
+
+    /**
+     * Constructs a new <code>JosmPasswordField</code> initialized
+     * with the specified text.  The document model is set to the
+     * default, and the number of columns to 0.
+     *
+     * @param text the text to be displayed, <code>null</code> if none
+     */
+    public JosmPasswordField(String text) {
+        super(text);
+        workaroundJdkBug6322854(this);
+    }
+    
+    /**
+     * Implements a workaround to <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6322854">JDK bug 6322854</a>.
+     * @param text The {@link JTextComponent} to protect.
+     */
+    public static final void workaroundJdkBug6322854(final JTextComponent text) {
+        if (text != null) {
+            text.getActionMap().put("paste", new Action() {
+                
+                private final Action pasteAction = TransferHandler.getPasteAction();
+                
+                @Override
+                public void actionPerformed(ActionEvent e) {
+                    try {
+                        pasteAction.actionPerformed(e);
+                    } catch (NullPointerException npe) {
+                        System.err.println("NullPointerException occured because of JDK bug 6322854. "
+                                +"Copy/Paste operation has not been performed. Please complain to Oracle: "+
+                                "http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6322854");
+                    }
+                }
+                
+                @Override
+                public void setEnabled(boolean b) {
+                    pasteAction.setEnabled(b);
+                }
+                
+                @Override
+                public void removePropertyChangeListener(PropertyChangeListener listener) {
+                    pasteAction.removePropertyChangeListener(listener);
+                }
+                
+                @Override
+                public void putValue(String key, Object value) {
+                    pasteAction.putValue(key, value);
+                }
+                
+                @Override
+                public boolean isEnabled() {
+                    return pasteAction.isEnabled();
+                }
+                
+                @Override
+                public Object getValue(String key) {
+                    return pasteAction.getValue(key);
+                }
+                
+                @Override
+                public void addPropertyChangeListener(PropertyChangeListener listener) {
+                    pasteAction.addPropertyChangeListener(listener);
+                }
+            });
+        }
+    }
+}
