@@ -240,7 +240,7 @@ public void setPrimitiveAsString( boolean primitiveAsString ) {
240240 *
241241 * @param defaultEncoding
242242 */
243- public void setDefaultEncoding (String defaultEncoding ) {
243+ public void setDefaultEncoding ( String defaultEncoding ) {
244244 this .defaultEncoding = defaultEncoding ;
245245 }
246246
@@ -257,7 +257,7 @@ public void setDefaultEncoding(String defaultEncoding) {
257257 *
258258 * @param compressEnable <CODE>true</CODE> to enable compression, <CODE>false</CODE> to disable compression
259259 */
260- public void setCompressEnable (boolean compressEnable ) {
260+ public void setCompressEnable ( boolean compressEnable ) {
261261 this .compressEnable = compressEnable ;
262262 }
263263
@@ -271,7 +271,7 @@ public void setCompressEnable(boolean compressEnable) {
271271 *
272272 * @param compressThreshold required length of data to consider compression
273273 */
274- public void setCompressThreshold (long compressThreshold ) {
274+ public void setCompressThreshold ( long compressThreshold ) {
275275 this .compressThreshold = compressThreshold ;
276276 }
277277
@@ -291,8 +291,8 @@ public boolean keyExists( String key ) {
291291 * @param key the key to be removed
292292 * @return <code>true</code>, if the data was deleted successfully
293293 */
294- public boolean delete (String key ) {
295- return delete (key , null , null );
294+ public boolean delete ( String key ) {
295+ return delete ( key , null , null );
296296 }
297297
298298 /**
@@ -302,8 +302,8 @@ public boolean delete(String key) {
302302 * @param expiry when to expire the record.
303303 * @return <code>true</code>, if the data was deleted successfully
304304 */
305- public boolean delete (String key , Date expiry ) {
306- return delete (key , null , expiry );
305+ public boolean delete ( String key , Date expiry ) {
306+ return delete ( key , null , expiry );
307307 }
308308
309309 /**
@@ -322,6 +322,11 @@ public boolean delete(String key, Date expiry) {
322322 */
323323 public boolean delete ( String key , Integer hashCode , Date expiry ) {
324324
325+ if ( key == null ) {
326+ log .error ( "null value for key passed to delete()" );
327+ return false ;
328+ }
329+
325330 // get SockIO obj from hash or from key
326331 SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock ( key , hashCode );
327332
@@ -423,8 +428,8 @@ public boolean set( String key, Object value, Date expiry ) {
423428 * @param hashCode if not null, then the int hashcode to use
424429 * @return true, if the data was successfully stored
425430 */
426- public boolean set (String key , Object value , Date expiry , Integer hashCode ) {
427- return set ("set" , key , value , expiry , hashCode , primitiveAsString );
431+ public boolean set ( String key , Object value , Date expiry , Integer hashCode ) {
432+ return set ( "set" , key , value , expiry , hashCode , primitiveAsString );
428433 }
429434
430435 /**
@@ -434,8 +439,8 @@ public boolean set(String key, Object value, Date expiry, Integer hashCode) {
434439 * @param value value to store
435440 * @return true, if the data was successfully stored
436441 */
437- public boolean add (String key , Object value ) {
438- return set ("add" , key , value , null , null , primitiveAsString );
442+ public boolean add ( String key , Object value ) {
443+ return set ( "add" , key , value , null , null , primitiveAsString );
439444 }
440445
441446 /**
@@ -446,8 +451,8 @@ public boolean add(String key, Object value) {
446451 * @param hashCode if not null, then the int hashcode to use
447452 * @return true, if the data was successfully stored
448453 */
449- public boolean add (String key , Object value , Integer hashCode ) {
450- return set ("add" , key , value , null , hashCode , primitiveAsString );
454+ public boolean add ( String key , Object value , Integer hashCode ) {
455+ return set ( "add" , key , value , null , hashCode , primitiveAsString );
451456 }
452457
453458 /**
@@ -458,8 +463,8 @@ public boolean add(String key, Object value, Integer hashCode) {
458463 * @param expiry when to expire the record
459464 * @return true, if the data was successfully stored
460465 */
461- public boolean add (String key , Object value , Date expiry ) {
462- return set ("add" , key , value , expiry , null , primitiveAsString );
466+ public boolean add ( String key , Object value , Date expiry ) {
467+ return set ( "add" , key , value , expiry , null , primitiveAsString );
463468 }
464469
465470 /**
@@ -471,8 +476,8 @@ public boolean add(String key, Object value, Date expiry) {
471476 * @param hashCode if not null, then the int hashcode to use
472477 * @return true, if the data was successfully stored
473478 */
474- public boolean add (String key , Object value , Date expiry , Integer hashCode ) {
475- return set ("add" , key , value , expiry , hashCode , primitiveAsString );
479+ public boolean add ( String key , Object value , Date expiry , Integer hashCode ) {
480+ return set ( "add" , key , value , expiry , hashCode , primitiveAsString );
476481 }
477482
478483 /**
@@ -482,8 +487,8 @@ public boolean add(String key, Object value, Date expiry, Integer hashCode) {
482487 * @param value value to store
483488 * @return true, if the data was successfully stored
484489 */
485- public boolean replace (String key , Object value ) {
486- return set ("replace" , key , value , null , null , primitiveAsString );
490+ public boolean replace ( String key , Object value ) {
491+ return set ( "replace" , key , value , null , null , primitiveAsString );
487492 }
488493
489494 /**
@@ -494,8 +499,8 @@ public boolean replace(String key, Object value) {
494499 * @param hashCode if not null, then the int hashcode to use
495500 * @return true, if the data was successfully stored
496501 */
497- public boolean replace (String key , Object value , Integer hashCode ) {
498- return set ("replace" , key , value , null , hashCode , primitiveAsString );
502+ public boolean replace ( String key , Object value , Integer hashCode ) {
503+ return set ( "replace" , key , value , null , hashCode , primitiveAsString );
499504 }
500505
501506 /**
@@ -506,8 +511,8 @@ public boolean replace(String key, Object value, Integer hashCode) {
506511 * @param expiry when to expire the record
507512 * @return true, if the data was successfully stored
508513 */
509- public boolean replace (String key , Object value , Date expiry ) {
510- return set ("replace" , key , value , expiry , null , primitiveAsString );
514+ public boolean replace ( String key , Object value , Date expiry ) {
515+ return set ( "replace" , key , value , expiry , null , primitiveAsString );
511516 }
512517
513518 /**
@@ -519,8 +524,8 @@ public boolean replace(String key, Object value, Date expiry) {
519524 * @param hashCode if not null, then the int hashcode to use
520525 * @return true, if the data was successfully stored
521526 */
522- public boolean replace (String key , Object value , Date expiry , Integer hashCode ) {
523- return set ("replace" , key , value , expiry , hashCode , primitiveAsString );
527+ public boolean replace ( String key , Object value , Date expiry , Integer hashCode ) {
528+ return set ( "replace" , key , value , expiry , hashCode , primitiveAsString );
524529 }
525530
526531 /**
@@ -545,6 +550,11 @@ public boolean replace(String key, Object value, Date expiry, Integer hashCode)
545550 */
546551 private boolean set ( String cmdname , String key , Object value , Date expiry , Integer hashCode , boolean asString ) {
547552
553+ if ( cmdname == null || cmdname .trim ().equals ( "" ) || key == null ) {
554+ log .error ( "key is null or cmd is null/empty for set()" );
555+ return false ;
556+ }
557+
548558 // get SockIO obj
549559 SockIOPool .SockIO sock = SockIOPool .getInstance ( poolName ).getSock ( key , hashCode );
550560
@@ -693,7 +703,7 @@ else if ( NOTSTORED.equals( line ) ) {
693703 * @return true/false indicating success
694704 */
695705 public boolean storeCounter ( String key , long counter ) {
696- return set ( "set" , key , new Long (counter ), null , null , true );
706+ return set ( "set" , key , new Long ( counter ), null , null , true );
697707 }
698708
699709 /**
@@ -715,8 +725,8 @@ public boolean storeCounter( String key, Long counter ) {
715725 * @param hashCode if not null, then the int hashcode to use
716726 * @return true/false indicating success
717727 */
718- public boolean storeCounter (String key , Long counter , Integer hashCode ) {
719- return set ("set" , key , counter , null , hashCode , true );
728+ public boolean storeCounter ( String key , Long counter , Integer hashCode ) {
729+ return set ( "set" , key , counter , null , hashCode , true );
720730 }
721731
722732 /**
@@ -725,8 +735,8 @@ public boolean storeCounter(String key, Long counter, Integer hashCode) {
725735 * @param key cache ket
726736 * @return counter value or -1 if not found
727737 */
728- public long getCounter (String key ) {
729- return getCounter (key , null );
738+ public long getCounter ( String key ) {
739+ return getCounter ( key , null );
730740 }
731741
732742 /**
@@ -736,14 +746,20 @@ public long getCounter(String key) {
736746 * @param hashCode if not null, then the int hashcode to use
737747 * @return counter value or -1 if not found
738748 */
739- public long getCounter (String key , Integer hashCode ) {
749+ public long getCounter ( String key , Integer hashCode ) {
750+
751+ if ( key == null ) {
752+ log .error ( "null key for getCounter()" );
753+ return -1 ;
754+ }
755+
740756 long counter = -1 ;
741757 try {
742758 counter = Long .parseLong ( (String )get ( key , hashCode , true ) );
743759 }
744- catch (Exception ex ) {
760+ catch ( Exception ex ) {
745761 // not found or error getting out
746- log .error ("counter not found at key: " + key );
762+ log .error ( "counter not found at key: " + key );
747763 }
748764
749765 return counter ;
@@ -755,8 +771,8 @@ public long getCounter(String key, Integer hashCode) {
755771 * @param key key where the data is stored
756772 * @return -1, if the key is not found, the value after incrementing otherwise
757773 */
758- public long incr (String key ) {
759- return incrdecr ("incr" , key , 1 , null );
774+ public long incr ( String key ) {
775+ return incrdecr ( "incr" , key , 1 , null );
760776 }
761777
762778 /**
@@ -766,8 +782,8 @@ public long incr(String key) {
766782 * @param inc how much to increment by
767783 * @return -1, if the key is not found, the value after incrementing otherwise
768784 */
769- public long incr (String key , long inc ) {
770- return incrdecr ("incr" , key , inc , null );
785+ public long incr ( String key , long inc ) {
786+ return incrdecr ( "incr" , key , inc , null );
771787 }
772788
773789 /**
@@ -778,8 +794,8 @@ public long incr(String key, long inc) {
778794 * @param hashCode if not null, then the int hashcode to use
779795 * @return -1, if the key is not found, the value after incrementing otherwise
780796 */
781- public long incr (String key , long inc , Integer hashCode ) {
782- return incrdecr ("incr" , key , inc , hashCode );
797+ public long incr ( String key , long inc , Integer hashCode ) {
798+ return incrdecr ( "incr" , key , inc , hashCode );
783799 }
784800
785801 /**
@@ -788,8 +804,8 @@ public long incr(String key, long inc, Integer hashCode) {
788804 * @param key key where the data is stored
789805 * @return -1, if the key is not found, the value after incrementing otherwise
790806 */
791- public long decr (String key ) {
792- return incrdecr ("decr" , key , 1 , null );
807+ public long decr ( String key ) {
808+ return incrdecr ( "decr" , key , 1 , null );
793809 }
794810
795811 /**
@@ -799,8 +815,8 @@ public long decr(String key) {
799815 * @param inc how much to increment by
800816 * @return -1, if the key is not found, the value after incrementing otherwise
801817 */
802- public long decr (String key , long inc ) {
803- return incrdecr ("decr" , key , inc , null );
818+ public long decr ( String key , long inc ) {
819+ return incrdecr ( "decr" , key , inc , null );
804820 }
805821
806822 /**
@@ -811,8 +827,8 @@ public long decr(String key, long inc) {
811827 * @param hashCode if not null, then the int hashcode to use
812828 * @return -1, if the key is not found, the value after incrementing otherwise
813829 */
814- public long decr (String key , long inc , Integer hashCode ) {
815- return incrdecr ("decr" , key , inc , hashCode );
830+ public long decr ( String key , long inc , Integer hashCode ) {
831+ return incrdecr ( "decr" , key , inc , hashCode );
816832 }
817833
818834 /**
0 commit comments