diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java index 1435e9919..db59a54a2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/HttpConfig.java @@ -44,13 +44,16 @@ package org.eclipse.jgit.transport; +import java.io.IOException; import java.net.URISyntaxException; import java.text.MessageFormat; import java.util.Set; import java.util.function.Supplier; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.StringUtils; import org.eclipse.jgit.util.SystemReader; @@ -142,13 +145,13 @@ public boolean matchConfigValue(String s) { } } - private final int postBuffer; + private int postBuffer; - private final boolean sslVerify; + private boolean sslVerify; - private final HttpRedirectMode followRedirects; + private HttpRedirectMode followRedirects; - private final int maxRedirects; + private int maxRedirects; /** * @return the value of the "http.postBuffer" setting @@ -187,6 +190,32 @@ public int getMaxRedirects() { * to get the configuration values for */ public HttpConfig(Config config, URIish uri) { + init(config, uri); + } + + /** + * Creates a {@link HttpConfig} that reads values solely from the user + * config. + * + * @param uri + * to get the configuration values for + */ + public HttpConfig(URIish uri) { + FileBasedConfig userConfig = SystemReader.getInstance() + .openUserConfig(null, FS.DETECTED); + try { + userConfig.load(); + } catch (IOException | ConfigInvalidException e) { + // Log it and then work with default values. + LOG.error(MessageFormat.format(JGitText.get().userConfigFileInvalid, + userConfig.getFile().getAbsolutePath(), e)); + init(new Config(), uri); + return; + } + init(userConfig, uri); + } + + private void init(Config config, URIish uri) { // Set defaults from the section first int postBufferSize = config.getInt(HTTP, POST_BUFFER_KEY, 1 * 1024 * 1024); @@ -220,17 +249,6 @@ public HttpConfig(Config config, URIish uri) { maxRedirects = redirectLimit; } - /** - * Creates a {@link HttpConfig} that reads values solely from the user - * config. - * - * @param uri - * to get the configuration values for - */ - public HttpConfig(URIish uri) { - this(SystemReader.getInstance().openUserConfig(null, FS.DETECTED), uri); - } - /** * Determines the best match from a set of subsection names (representing * prefix URLs) for the given {@link URIish}.