Catch unexpected PatternSyntaxException and convert it to InvalidPatternException. Log such errors, do not silently ignore them. Bug: 463581 Change-Id: Id0936d9816769ec0cfae1898beda0f7a3c146e67 Signed-off-by: Andrey Loskutov <loskutov@gmx.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>tags/v4.1.0.201509280440-r
@@ -328,6 +328,7 @@ invalidId=Invalid id: {0} | |||
invalidId0=Invalid id | |||
invalidIdLength=Invalid id length {0}; should be {1} | |||
invalidIgnoreParamSubmodule=Found invalid ignore param for submodule {0}. | |||
invalidIgnoreRule=Exception caught while parsing ignore rule ''{0}''. | |||
invalidIntegerValue=Invalid integer value: {0}.{1}={2} | |||
invalidKey=Invalid key: {0} | |||
invalidLineInConfigFile=Invalid line in config file |
@@ -47,6 +47,8 @@ import static org.eclipse.jgit.ignore.internal.IMatcher.NO_MATCH; | |||
import org.eclipse.jgit.errors.InvalidPatternException; | |||
import org.eclipse.jgit.ignore.internal.IMatcher; | |||
import org.eclipse.jgit.ignore.internal.PathMatcher; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
/** | |||
* "Fast" (compared with IgnoreRule) git ignore rule implementation supporting | |||
@@ -57,6 +59,8 @@ import org.eclipse.jgit.ignore.internal.PathMatcher; | |||
* @since 3.6 | |||
*/ | |||
public class FastIgnoreRule { | |||
private final static Logger LOG = LoggerFactory | |||
.getLogger(FastIgnoreRule.class); | |||
/** | |||
* Character used as default path separator for ignore entries | |||
@@ -121,6 +125,7 @@ public class FastIgnoreRule { | |||
Character.valueOf(PATH_SEPARATOR), dirOnly); | |||
} catch (InvalidPatternException e) { | |||
m = NO_MATCH; | |||
LOG.error(e.getMessage(), e); | |||
} | |||
this.matcher = m; | |||
} |
@@ -44,13 +44,16 @@ package org.eclipse.jgit.ignore.internal; | |||
import static java.lang.Character.isLetter; | |||
import java.text.MessageFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.regex.Pattern; | |||
import java.util.regex.PatternSyntaxException; | |||
import org.eclipse.jgit.errors.InvalidPatternException; | |||
import org.eclipse.jgit.ignore.FastIgnoreRule; | |||
import org.eclipse.jgit.internal.JGitText; | |||
/** | |||
* Various {@link String} related utility methods, written mostly to avoid | |||
@@ -367,7 +370,16 @@ public class Strings { | |||
if (in_brackets > 0) | |||
throw new InvalidPatternException("Not closed bracket?", pattern); //$NON-NLS-1$ | |||
return Pattern.compile(sb.toString()); | |||
try { | |||
return Pattern.compile(sb.toString()); | |||
} catch (PatternSyntaxException e) { | |||
InvalidPatternException patternException = new InvalidPatternException( | |||
MessageFormat.format(JGitText.get().invalidIgnoreRule, | |||
pattern), | |||
pattern); | |||
patternException.initCause(e); | |||
throw patternException; | |||
} | |||
} | |||
/** |
@@ -387,6 +387,7 @@ public class JGitText extends TranslationBundle { | |||
/***/ public String invalidId0; | |||
/***/ public String invalidIdLength; | |||
/***/ public String invalidIgnoreParamSubmodule; | |||
/***/ public String invalidIgnoreRule; | |||
/***/ public String invalidIntegerValue; | |||
/***/ public String invalidKey; | |||
/***/ public String invalidLineInConfigFile; |