From 6a07201844df2a9a1c86ced4b03c7433ce3e4483 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 13 Feb 2012 04:50:12 +0000 Subject: [PATCH] don't fail test due to jre bugs in String.toLowerCase git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1243415 13f79535-47bb-0310-9956-ffa450edef68 --- .../miscellaneous/PatternAnalyzerTest.java | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/PatternAnalyzerTest.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/PatternAnalyzerTest.java index e998802ced9..3b1b2296f3a 100644 --- a/modules/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/PatternAnalyzerTest.java +++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/miscellaneous/PatternAnalyzerTest.java @@ -19,6 +19,7 @@ package org.apache.lucene.analysis.miscellaneous; import java.io.IOException; import java.io.StringReader; +import java.lang.Thread.UncaughtExceptionHandler; import java.util.Arrays; import java.util.regex.Pattern; @@ -137,6 +138,40 @@ public class PatternAnalyzerTest extends BaseTokenStreamTestCase { /** blast some random strings through the analyzer */ public void testRandomStrings() throws Exception { Analyzer a = new PatternAnalyzer(TEST_VERSION_CURRENT, Pattern.compile(","), true, StopAnalyzer.ENGLISH_STOP_WORDS_SET); - checkRandomData(random, a, 10000*RANDOM_MULTIPLIER); + + // dodge jre bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7104012 + final UncaughtExceptionHandler savedHandler = Thread.getDefaultUncaughtExceptionHandler(); + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread thread, Throwable throwable) { + assumeTrue("not failing due to jre bug ", !isJREBug7104012(throwable)); + // otherwise its some other bug, pass to default handler + savedHandler.uncaughtException(thread, throwable); + } + }); + + try { + Thread.getDefaultUncaughtExceptionHandler(); + checkRandomData(random, a, 10000*RANDOM_MULTIPLIER); + } catch (ArrayIndexOutOfBoundsException ex) { + assumeTrue("not failing due to jre bug ", !isJREBug7104012(ex)); + throw ex; // otherwise rethrow + } finally { + Thread.setDefaultUncaughtExceptionHandler(savedHandler); + } + } + + static boolean isJREBug7104012(Throwable t) { + if (!(t instanceof ArrayIndexOutOfBoundsException)) { + return false; + } + StackTraceElement trace[] = t.getStackTrace(); + for (StackTraceElement st : trace) { + if ("java.text.RuleBasedBreakIterator".equals(st.getClassName()) + && "lookupBackwardState".equals(st.getMethodName())) { + return true; + } + } + return false; } }