diff --git a/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java b/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java index e37df78c..ef44f2ff 100644 --- a/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java +++ b/evcache-client/test/com/netflix/evcache/test/EVCacheTestDI.java @@ -94,6 +94,8 @@ public void testKeySizeCheck() throws Exception { } catch(Exception e) { exceptionThrown = true; if (log.isDebugEnabled()) log.debug("Check key length: " + longKey + ": INVALID"); + assertTrue(e.getMessage().contains(longKey), "Error message should include the invalid key."); + assertTrue(e.getMessage().contains(Integer.toString(longKey.length())), "Error message should include the key length of the invalid key."); } assertTrue(exceptionThrown); } diff --git a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java index 4a23eebe..fd38c266 100644 --- a/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java +++ b/evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java @@ -215,7 +215,9 @@ EVCacheKey getEVCacheKey(final String key) { } if (canonicalKey.length() > this.maxKeyLength.get() && !hashKey.get() && !autoHashKeys.get()) { - throw new IllegalArgumentException("Key is too long (maxlen = " + this.maxKeyLength.get() + ')'); + final String errMsg = String.format("CanonicalKey ``%s`` is too long (maxLen = %d, keyLen = %d, canonicalKeyLen = %d)", canonicalKey, this.maxKeyLength.get(), key.length(), canonicalKey.length()); + log.warn(errMsg); + throw new IllegalArgumentException(errMsg); } boolean shouldHashKeyAtAppLevel = hashKey.get() || (canonicalKey.length() > this.maxKeyLength.get() && autoHashKeys.get());