ContentTypeUtil: Add singleton scope
Before this change, migrating repositories like [1], which has a lot of
refs, to Gerrit caused a timeout and the push wasn't successful. Classes
injecting ContentTypeUtil, InvalidLineEndingValidator,
ContentTypeValidator and BlockedKeywordValidator were trying to
intialize the ContentTypeValidator class a lot of time causing an
infinite loop. This loop is probably trying to load the cache
consentatly
This change adds the singleton scope to initialize the class one time
only preventing the infinite loop.
[1] https://github.com/angular/angular.git
Bug: Issue 14784
Change-Id: Ic5bb8eaebf72a7346ebe2514fb01e62118368c23
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java
index bb6f9db..517d245 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/ContentTypeUtil.java
@@ -24,6 +24,7 @@
import com.google.gerrit.server.config.ProjectConfigEntry;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
+import com.google.inject.Scopes;
import com.google.inject.name.Named;
import java.io.IOException;
import java.io.InputStream;
@@ -41,7 +42,7 @@
@Override
protected void configure() {
- bind(ContentTypeUtil.class);
+ bind(ContentTypeUtil.class).in(Scopes.SINGLETON);
bind(ProjectConfigEntry.class)
.annotatedWith(Exports.named(KEY_BINARY_TYPES))
.toInstance(