Index: applications/editors/josm/plugins/native-password-manager/.classpath
===================================================================
--- applications/editors/josm/plugins/native-password-manager/.classpath	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/.classpath	(revision 30822)
@@ -2,7 +2,7 @@
 <classpath>
 	<classpathentry kind="src" path="src"/>
-	<classpathentry kind="lib" path="lib/jna.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/JOSM"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/JOSM-jna"/>
 	<classpathentry kind="output" path="build"/>
 </classpath>
Index: applications/editors/josm/plugins/native-password-manager/README
===================================================================
--- applications/editors/josm/plugins/native-password-manager/README	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/README	(revision 30822)
@@ -18,6 +18,7 @@
 
 Original code:
-    http://hg.netbeans.org/main/file/524f40b94a30/keyring.impl  and
-    http://hg.netbeans.org/main/file/524f40b94a30/keyring
+    http://hg.netbeans.org/main/file/9413a02b6f0c/keyring.impl
+    http://hg.netbeans.org/main/file/9413a02b6f0c/keyring
+    http://hg.netbeans.org/main/file/9413a02b6f0c/keyring.fallback
 Patch:
     netbeans-keyring-patches.diff
Index: applications/editors/josm/plugins/native-password-manager/build.xml
===================================================================
--- applications/editors/josm/plugins/native-password-manager/build.xml	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/build.xml	(revision 30822)
@@ -6,4 +6,10 @@
     <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
     <property name="plugin.main.version" value="7001"/>
+    <property name="plugin.author" value="Paul Hartmann"/>
+    <property name="plugin.class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/>
+    <property name="plugin.description" value="Use your system''s password manager to store the API username and password. (KWallet and gnome-keyring are supported.)"/>
+    <property name="plugin.icon" value="images/lock24x24.png"/>
+    <property name="plugin.link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/Native_Password_Manager"/>
+    <property name="plugin.requires" value="jna"/>
 
     <!--
@@ -14,66 +20,7 @@
     <import file="../build-common.xml"/>
 
-    <!-- classpath -->
-    <path id="classpath">
-        <fileset dir="${plugin.lib.dir}" includes="**/*.jar"/>
-        <pathelement path="${josm}"/>
-    </path>
-    <!--
-    **********************************************************
-    ** compile - complies the source tree
-    ** Overrides the target from build-common.xml
-    **********************************************************
-    -->
-    <target name="compile" depends="init">
-        <echo message="compiling sources for ${plugin.jar} ..."/>
-        <javac srcdir="src" classpathref="classpath" debug="true" destdir="${plugin.build.dir}" includeantruntime="false">
-            <compilerarg value="-Xlint:deprecation"/>
-            <compilerarg value="-Xlint:unchecked"/>
-        </javac>
-    </target>
-
-    <!--
-    **********************************************************
-    ** dist - creates the plugin jar
-    **********************************************************
-    -->
-    <target name="dist" depends="compile,revision">
-        <echo message="creating ${ant.project.name}.jar ... "/>
-        <copy todir="${plugin.build.dir}/images">
-            <fileset dir="images"/>
-        </copy>
-        <copy todir="${plugin.build.dir}/data">
-            <fileset dir="data"/>
-        </copy>
-        <copy todir="${plugin.build.dir}">
-            <fileset dir=".">
-                <include name="README"/>
-                <include name="LICENSE"/>
-                <include name="gpl-2-cp.txt"/>
-                <include name="gpl-3.txt"/>
-            </fileset>
-        </copy>
-        <jar destfile="${plugin.jar}" basedir="${plugin.build.dir}">
-        <!--
-        ************************************************
-        ** configure these properties. Most of them will be copied to the plugins
-        ** manifest file. Property values will also show up in the list available
-        ** plugins: http://josm.openstreetmap.de/wiki/Plugins.
-        **
-        ************************************************
-        -->
-            <manifest>
-                <attribute name="Author" value="Paul Hartmann"/>
-                <attribute name="Plugin-Class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/>
-                <attribute name="Main-Class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/>
-                <attribute name="Plugin-Date" value="${version.entry.commit.date}"/>
-                <attribute name="Plugin-Description" value="Use your system''s password manager to store the API username and password. (KWallet and gnome-keyring are supported.)"/>
-                <attribute name="Plugin-Icon" value="images/lock24x24.png"/>
-                <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/wiki/JOSM/Plugins/Native_Password_Manager"/>
-                <attribute name="Plugin-Mainversion" value="${plugin.main.version}"/>
-                <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
-            </manifest>
-            <zipfileset src="${plugin.lib.dir}/jna.jar"/>
-        </jar>
-    </target>
+    <fileset id="plugin.requires.jars" dir="${plugin.dist.dir}">
+        <include name="jna.jar"/>
+    </fileset>
+    
 </project>
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java	(revision 30822)
@@ -43,7 +43,8 @@
 package org.netbeans.modules.keyring.fallback;
 
-import java.util.UUID;
+import java.security.SecureRandom;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import org.netbeans.modules.keyring.spi.EncryptionProvider;
 import org.netbeans.spi.keyring.KeyringProvider;
@@ -73,4 +74,5 @@
     }
 
+    @Override
     public boolean enabled() {
         if (encryption.enabled()) {
@@ -86,5 +88,7 @@
     private boolean testSampleKey() {
         encryption.freshKeyring(true);
-        if (_save(SAMPLE_KEY, (SAMPLE_KEY + UUID.randomUUID()).toCharArray(),
+        byte[] randomArray = new byte[36];
+        new SecureRandom().nextBytes(randomArray);
+        if (_save(SAMPLE_KEY, (SAMPLE_KEY + new String(randomArray)).toCharArray(),
                 "Sample value ensuring that decryption is working.")) {
             LOG.fine("saved sample key");
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeKeyringLibrary.java	(revision 30822)
@@ -43,8 +43,17 @@
 package org.netbeans.modules.keyring.gnome;
 
+import com.sun.jna.DefaultTypeMapper;
+import com.sun.jna.FromNativeContext;
 import com.sun.jna.Library;
 import com.sun.jna.Native;
 import com.sun.jna.Pointer;
 import com.sun.jna.Structure;
+import com.sun.jna.ToNativeContext;
+import com.sun.jna.TypeConverter;
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
 
 /**
@@ -55,5 +64,41 @@
 public interface GnomeKeyringLibrary extends Library {
 
-    GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary) Native.loadLibrary("gnome-keyring", GnomeKeyringLibrary.class);
+    class LibFinder {
+        private static final String GENERIC = "gnome-keyring";
+        // http://packages.ubuntu.com/search?suite=precise&arch=any&mode=exactfilename&searchon=contents&keywords=libgnome-keyring.so.0
+        private static final String EXPLICIT_ONEIRIC = "/usr/lib/libgnome-keyring.so.0";
+        private static Object load(Map<?,?> options) {
+            try {
+                return Native.loadLibrary(GENERIC, GnomeKeyringLibrary.class, options);
+            } catch (UnsatisfiedLinkError x) {
+                // #203735: on Oneiric, may have trouble finding right lib.
+                // Precise is using multiarch (#211401) which should work automatically using JNA 3.4+ (#211403).
+                // Unclear if this workaround is still needed for Oneiric with 3.4, but seems harmless to leave it in for now.
+                if (new File(EXPLICIT_ONEIRIC).isFile()) {
+                    return Native.loadLibrary(EXPLICIT_ONEIRIC, GnomeKeyringLibrary.class, options);
+                } else {
+                    throw x;
+                }
+            }
+        }
+        private LibFinder() {}
+    }
+
+    GnomeKeyringLibrary LIBRARY = (GnomeKeyringLibrary) LibFinder.load(Collections.singletonMap(OPTION_TYPE_MAPPER, new DefaultTypeMapper() {
+        {
+            addTypeConverter(Boolean.TYPE, new TypeConverter() { // #198921
+                @Override public Object toNative(Object value, ToNativeContext context) {
+                    return Boolean.TRUE.equals(value) ? 1 : 0;
+                }
+                @Override public Object fromNative(Object value, FromNativeContext context) {
+                    return ((Integer) value).intValue() != 0;
+                }
+                @Override public Class<?> nativeType() {
+                    // gint is 32-bit int
+                    return Integer.class;
+                }
+            });
+        }
+    }));
 
     boolean gnome_keyring_is_available();
@@ -98,4 +143,14 @@
         public /*GnomeKeyringAttributeList*/Pointer attributes;
         public String secret;
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList( new String[] {
+                "keyring",
+                "item_id",
+                "attributes",
+                "secret",
+            } );
+        }
     }
 
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/gnome/GnomeProvider.java	(revision 30822)
@@ -43,9 +43,15 @@
 package org.netbeans.modules.keyring.gnome;
 
-import com.sun.jna.Pointer;
+import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GNOME_KEYRING_ITEM_GENERIC_SECRET;
+import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GnomeKeyringAttribute_SIZE;
+import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.LIBRARY;
+
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import static org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.*;
+
+import org.netbeans.modules.keyring.gnome.GnomeKeyringLibrary.GnomeKeyringFound;
 import org.netbeans.spi.keyring.KeyringProvider;
+
+import com.sun.jna.Pointer;
 
 public class GnomeProvider implements KeyringProvider {
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/kde/KWalletProvider.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/kde/KWalletProvider.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/kde/KWalletProvider.java	(revision 30822)
@@ -70,14 +70,14 @@
         }
         CommandResult result = runCommand("isEnabled");
-        if(new String(result.retVal).equals("true")) {
+        if(new String(result.retVal).equals("true")) {        
             return updateHandler();
-        }
+        }                   
         return false;
-    };
+    }
 
     @Override
     public char[] read(String key){
         if (updateHandler()){
-            CommandResult result = runCommand("readPassword", handler, getApplicationName(), key.toCharArray(), getApplicationName(true));
+            CommandResult result = runCommand("readPassword", handler, getApplicationName(), key.toCharArray(), getApplicationName());
             if (result.exitCode != 0){
                 warning("read action returned not 0 exitCode");
@@ -87,5 +87,5 @@
         return null;
         //throw new KwalletException("read");
-    };
+    }
 
     @Override
@@ -95,5 +95,5 @@
         if (updateHandler()){
             CommandResult result = runCommand("writePassword", handler , getApplicationName()
-                    , key.toCharArray(), password , getApplicationName(true));
+                    , key.toCharArray(), password , getApplicationName());
             if (result.exitCode != 0 || (new String(result.retVal)).equals("-1")){
                 warning("save action failed");
@@ -102,5 +102,5 @@
         }
         //throw new KwalletException("save");
-    };
+    }
 
     @Override
@@ -108,5 +108,5 @@
         if (updateHandler()){
             CommandResult result = runCommand("removeEntry" ,handler,
-            getApplicationName() , key.toCharArray() , getApplicationName(true));
+            getApplicationName() , key.toCharArray() , getApplicationName());
              if (result.exitCode != 0  || (new String(result.retVal)).equals("-1")){
                 warning("delete action failed");
@@ -115,5 +115,5 @@
         }
         //throw new KwalletException("delete");
-    };
+    }
 
     private boolean updateHandler(){
@@ -122,15 +122,15 @@
         }
         handler = new String(handler).equals("")? "0".toCharArray() : handler;
-        CommandResult result = runCommand("isOpen",handler);
+        CommandResult result = runCommand("isOpen",handler);          
         if(new String(result.retVal).equals("true")){
             return true;
         }
         char[] localWallet = defaultLocalWallet;
-        result = runCommand("localWallet");
-        if(result.exitCode == 0) {
+        result = runCommand("localWallet");                      
+        if(result.exitCode == 0) {                    
             localWallet = result.retVal;
         }
-
-        if(new String(localWallet).contains(".service")) {
+            
+        if(new String(localWallet).contains(".service")) {            
             //Temporary workaround for the bug in kdelibs/kdeui/util/kwallet.cpp
             //The bug was fixed http://svn.reviewboard.kde.org/r/5885/diff/
@@ -138,20 +138,20 @@
             return false;
         }
-        result = runCommand("open", localWallet , "0".toCharArray(), getApplicationName(true));
-        if(result.exitCode == 2) {
+        result = runCommand("open", localWallet , "0".toCharArray(), getApplicationName());
+        if(result.exitCode == 2) { 
             warning("time out happened while accessing KWallet");
             //don't try to open KWallet anymore until bug https://bugs.kde.org/show_bug.cgi?id=259229 is fixed
             timeoutHappened = true;
             return false;
-        }
+        }      
         if(result.exitCode != 0 || new String(result.retVal).equals("-1")) {
             warning("failed to access KWallet");
             return false;
-        }
+        }         
         handler = result.retVal;
         return true;
     }
-
-
+          
+    
 
     private CommandResult runCommand(String command,char[]... commandArgs) {
@@ -175,7 +175,8 @@
             }
             Process pr = rt.exec(argv);
-            String line;
-
+            
             try (BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()))) {
+
+                String line;
                 while((line = input.readLine()) != null) {
                     if (!retVal.equals("")){
@@ -183,8 +184,9 @@
                     }
                     retVal = retVal.concat(line);
-                }
-            }
-
+                }            
+            }
             try (BufferedReader input = new BufferedReader(new InputStreamReader(pr.getErrorStream()))) {
+
+                String line;
                 while((line = input.readLine()) != null) {
                     if (!errVal.equals("")){
@@ -199,5 +201,5 @@
                 logger.log(Level.FINE, "application exit with code {0} for commandString: {1}; errVal: {2}",
                             new Object[]{exitCode, Arrays.toString(argv), errVal});
-            }
+            }       
         } catch (InterruptedException ex) {
             logger.log(Level.FINE,
@@ -210,18 +212,14 @@
         }
         return new CommandResult(exitCode, retVal.trim().toCharArray(), errVal.trim());
-    }
+    }    
 
     private char[] getApplicationName(){
-        return getApplicationName(false);
-    }
-
-    private char[] getApplicationName(boolean version){
-        return "JOSM".toCharArray();
+        return "JOSM".toCharArray(); // NOI18N
     }
 
     private void warning(String descr) {
         logger.log(Level.WARNING, "Something went wrong: {0}", descr);
-    }
-
+    }      
+  
     private class CommandResult {
         private int exitCode;
@@ -231,5 +229,5 @@
             this.exitCode = exitCode;
             this.retVal = retVal;
-        }
+        }                        
     }
 
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java	(revision 30822)
@@ -77,5 +77,4 @@
 
     public void save(String key, char[] password, String description) {
-        delete(key); // XXX supposed to use SecKeychainItemModifyContent instead, but this seems like too much work
         try {
             byte[] serviceName = key.getBytes("UTF-8");
@@ -83,6 +82,14 @@
             // Keychain Access seems to expect UTF-8, so do not use Utils.chars2Bytes:
             byte[] data = new String(password).getBytes("UTF-8");
-            error("save", SecurityLibrary.LIBRARY.SecKeychainAddGenericPassword(null, serviceName.length, serviceName,
-                    accountName.length, accountName, data.length, data, null));
+            Pointer[] itemRef = new Pointer[1];
+            error("find (for save)", SecurityLibrary.LIBRARY.SecKeychainFindGenericPassword(null, serviceName.length, serviceName,
+                    accountName.length, accountName, null, null, itemRef));
+            if (itemRef[0] != null) {
+                error("save (update)", SecurityLibrary.LIBRARY.SecKeychainItemModifyContent(itemRef[0], null, data.length, data));
+                SecurityLibrary.LIBRARY.CFRelease(itemRef[0]);
+            } else {
+                error("save (new)", SecurityLibrary.LIBRARY.SecKeychainAddGenericPassword(null, serviceName.length, serviceName,
+                        accountName.length, accountName, data.length, data, null));
+            }
         } catch (UnsupportedEncodingException x) {
             LOG.log(Level.WARNING, null, x);
@@ -100,4 +107,5 @@
             if (itemRef[0] != null) {
                 error("delete", SecurityLibrary.LIBRARY.SecKeychainItemDelete(itemRef[0]));
+                SecurityLibrary.LIBRARY.CFRelease(itemRef[0]);
             }
         } catch (UnsupportedEncodingException x) {
@@ -108,6 +116,17 @@
     private static void error(String msg, int code) {
         if (code != 0 && code != /* errSecItemNotFound, always returned from find it seems */-25300) {
-            // XXX translate, but SecCopyErrorMessageString returns weird CFStringRef
-            LOG.warning(msg + ": " + code);
+            Pointer translated = SecurityLibrary.LIBRARY.SecCopyErrorMessageString(code, null);
+            String str;
+            if (translated == null) {
+                str = String.valueOf(code);
+            } else {
+                char[] buf = new char[(int) SecurityLibrary.LIBRARY.CFStringGetLength(translated)];
+                for (int i = 0; i < buf.length; i++) {
+                    buf[i] = SecurityLibrary.LIBRARY.CFStringGetCharacterAtIndex(translated, i);
+                }
+                SecurityLibrary.LIBRARY.CFRelease(translated);
+                str = new String(buf) + " (" + code + ")";
+            }
+            LOG.log(Level.WARNING, "{0}: {1}", new Object[] {msg, str});
         }
     }
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/SecurityLibrary.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/SecurityLibrary.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/SecurityLibrary.java	(revision 30822)
@@ -65,4 +65,11 @@
             );
 
+    int SecKeychainItemModifyContent(
+            Pointer/*SecKeychainItemRef*/ itemRef,
+            Pointer/*SecKeychainAttributeList**/ attrList,
+            int length,
+            byte[] data
+    );
+
     int SecKeychainFindGenericPassword(
             Pointer keychainOrArray,
@@ -73,5 +80,5 @@
             int[] passwordLength,
             Pointer[] passwordData,
-            Pointer[] itemRef
+            Pointer/*SecKeychainItemRef*/[] itemRef
             );
 
@@ -80,3 +87,23 @@
             );
 
+    Pointer/*CFString*/ SecCopyErrorMessageString(
+            int status,
+            Pointer reserved
+            );
+
+    // http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFStringRef/Reference/reference.html
+
+    long/*CFIndex*/ CFStringGetLength(
+            Pointer/*CFStringRef*/ theString
+    );
+
+    char/*UniChar*/ CFStringGetCharacterAtIndex(
+            Pointer/*CFStringRef*/ theString,
+            long/*CFIndex*/ idx
+    );
+
+    void CFRelease(
+            Pointer/*CFTypeRef*/ cf
+    );
+
 }
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/utils/Utils.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/utils/Utils.java	(revision 30822)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/utils/Utils.java	(revision 30822)
@@ -0,0 +1,65 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.keyring.utils;
+
+public class Utils {
+
+    private Utils() {}
+
+    public static byte[] chars2Bytes(char[] chars) {
+        byte[] bytes = new byte[chars.length * 2];
+        for (int i = 0; i < chars.length; i++) {
+            bytes[i * 2] = (byte) ((int)chars[i] / 256);
+            bytes[i * 2 + 1] = (byte) (chars[i] % 256);
+        }
+        return bytes;
+    }
+
+    public static char[] bytes2Chars(byte[] bytes) {
+        char[] result = new char[bytes.length / 2];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = (char) (((bytes[i * 2] & 0x00ff) * 256) + (bytes[i * 2 + 1] & 0x00ff));
+        }
+        return result;
+    }
+}
Index: applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/win32/Win32Protect.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/win32/Win32Protect.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/win32/Win32Protect.java	(revision 30822)
@@ -49,9 +49,12 @@
 import com.sun.jna.WString;
 import com.sun.jna.win32.StdCallLibrary;
+
 import java.util.Arrays;
+import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import org.netbeans.modules.keyring.impl.Utils;
+
+import org.netbeans.modules.keyring.utils.Utils;
 import org.netbeans.modules.keyring.spi.EncryptionProvider;
 
@@ -161,4 +164,12 @@
             ((Memory) pbData).clear();
         }
+
+        @Override
+        protected List<String> getFieldOrder() {
+            return Arrays.asList( new String[] {
+                "cbData",
+                "pbData",
+            } );
+        }
     }
 
Index: applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java
===================================================================
--- applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java	(revision 30821)
+++ applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java	(revision 30822)
@@ -460,4 +460,7 @@
     }
 
+    /**
+     * Close the dialog and discard all changes.
+     */
     class CancelAction extends AbstractAction {
         public CancelAction() {
@@ -478,4 +481,7 @@
     }
 
+    /**
+     * Go to the previous page.
+     */
     class BackAction extends AbstractAction {
         public BackAction() {
