aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsameb <sameb@google.com>2015-02-02 16:56:52 -0800
committerSam Berlin <sameb@google.com>2015-02-03 18:07:07 -0500
commit74519f5b0ac4cc00c58db242903dad26e27d47b2 (patch)
treefcd3cdaa6b283fd27a71e2581539406868728ed9
parente18906acc38e436613d01b0b96cf5c09623ec987 (diff)
downloadguice-74519f5b0ac4cc00c58db242903dad26e27d47b2.tar.gz
Only warn one per dependency, otherwise log spam can destroy disks. This time w/o using Sets.newConcurrentHashSet.,
------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=85377786
-rw-r--r--core/src/com/google/inject/internal/Errors.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/core/src/com/google/inject/internal/Errors.java b/core/src/com/google/inject/internal/Errors.java
index 87e0cc87..5ce3b429 100644
--- a/core/src/com/google/inject/internal/Errors.java
+++ b/core/src/com/google/inject/internal/Errors.java
@@ -20,6 +20,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
+import com.google.common.collect.Sets;
import com.google.inject.ConfigurationException;
import com.google.inject.CreationException;
import com.google.inject.Guice;
@@ -55,6 +56,7 @@ import java.util.Collection;
import java.util.Formatter;
import java.util.List;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -77,6 +79,9 @@ public final class Errors implements Serializable {
private static final Logger logger = Logger.getLogger(Guice.class.getName());
+ private static final Set<Dependency<?>> warnedDependencies =
+ Sets.newSetFromMap(new ConcurrentHashMap<Dependency<?>, Boolean>());
+
/**
* The root errors object. Used to access the list of error messages.
@@ -618,6 +623,10 @@ public final class Errors implements Serializable {
case IGNORE:
return value; // user doesn't care about injecting nulls to non-@Nullables.
case WARN:
+ // Warn only once, otherwise we spam logs too much.
+ if (!warnedDependencies.add(dependency)) {
+ return value;
+ }
logger.log(Level.WARNING,
"Guice injected null into parameter {0} of {1} (a {2}), please mark it @Nullable."
+ " Use -Dguice_check_nullable_provides_params=ERROR to turn this into an"