@@ -507,7 +507,7 @@ private void findNext() {
507507
508508 /** @see java.util.prefs.Preferences#put */
509509 public void put (final String key , final Object value ) {
510- p .put (safeKey (key ), value == null ? null : value . toString ( ));
510+ p .put (safeKey (key ), safeValue ( value ));
511511 }
512512
513513 /** @see java.util.prefs.Preferences#get(String, String) */
@@ -597,13 +597,13 @@ public String[] keys() {
597597
598598 /** @see java.util.prefs.Preferences#node(String) */
599599 public SmartPrefs node (final String pathName ) {
600- return new SmartPrefs (p .node (pathName ), log );
600+ return new SmartPrefs (p .node (safeName ( pathName ) ), log );
601601 }
602602
603603 /** @see java.util.prefs.Preferences#nodeExists(String) */
604604 public boolean nodeExists (final String pathName ) {
605605 try {
606- return p .nodeExists (pathName );
606+ return p .nodeExists (safeName ( pathName ) );
607607 }
608608 catch (final java .util .prefs .BackingStoreException exc ) {
609609 log .error (exc );
@@ -627,6 +627,16 @@ private String safeKey(final String key) {
627627 return makeSafe (key , java .util .prefs .Preferences .MAX_KEY_LENGTH );
628628 }
629629
630+ private String safeValue (final Object value ) {
631+ if (value == null ) return null ;
632+ return makeSafe (value .toString (),
633+ java .util .prefs .Preferences .MAX_VALUE_LENGTH );
634+ }
635+
636+ private String safeName (final String name ) {
637+ return makeSafe (name , java .util .prefs .Preferences .MAX_NAME_LENGTH );
638+ }
639+
630640 /**
631641 * This method limits the given string to the specified maximum length using
632642 * its latter characters prepended with "..." as needed.
0 commit comments