diff --git a/gradle/validation/validate-source-patterns.gradle b/gradle/validation/validate-source-patterns.gradle index b4c1f899535..540ee2962fc 100644 --- a/gradle/validation/validate-source-patterns.gradle +++ b/gradle/validation/validate-source-patterns.gradle @@ -173,8 +173,22 @@ class ValidateSourcePatternsTask extends DefaultTask { def validSPINameJavadocTag = ~$/(?s)\s*\*\s*@lucene\.spi\s+\{@value #NAME\}/$; def isLicense = { matcher, ratDocument -> - licenseMatcher.reset() - return lineSplitter.split(matcher.group(1)).any { licenseMatcher.match(ratDocument, it) } + boolean retValue = false + Exception rethrow = null + int retries = 5 + do { + try { + licenseMatcher.reset() + retValue = lineSplitter.split(matcher.group(1)).any { licenseMatcher.match(ratDocument, it) } + if (retValue) break + } catch (StringIndexOutOfBoundsException | RuntimeException e) { + logger.error("Exception thrown=" + e + ", retries: " + retries + ", matcher.group(1)=" + matcher.group(1)) + rethrow = e + } + } while (retries-- > 0) + + if (rethrow != null) throw rethrow + return retValue } def checkLicenseHeaderPrecedes = { f, description, contentPattern, commentPattern, text, ratDocument -> @@ -204,11 +218,12 @@ class ValidateSourcePatternsTask extends DefaultTask { progress.start(this.name, this.name) sourceFiles.each { f -> - try { - progress.progress("Scanning ${f.name}") - logger.debug('Scanning source file: {}', f); + progress.progress("Scanning ${f.name}") + logger.debug('Scanning source file: {}', f); - def text = f.getText('UTF-8'); + def text = f.getText('UTF-8'); + + try { invalidPatterns.each { pattern, name -> if (pattern.matcher(text).find()) { reportViolation(f, name); @@ -257,7 +272,7 @@ class ValidateSourcePatternsTask extends DefaultTask { } } catch (e) { e.printStackTrace() - throw new GradleException("Unhandled exception while validating patterns on file: " + f, e) + throw new GradleException("Unhandled exception while validating patterns on file: " + f + ", content: >>" + text + "<<", e) } }