[
https://issues.apache.org/jira/browse/LUCENE-10353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17469148#comment-17469148
]
Uwe Schindler commented on LUCENE-10353:
----------------------------------------
Hi, I did some quick test on my branch for LUCENE-10352. It works well an also
discovers bugs, but we should wait a bit.
The first problem I found was TypeTokenFilter that caused an NPE in accept(),
because the type was not checked for non-null.
The patch I used is here for later use, we have to change 2 places:
- inject "null" if the argument type is not primitive (primitives can't be
null) in 10% of all cases
- explicitely allow NPE in ctor, so add this to the list of allowed exceptions
{noformat}
.../test/org/apache/lucene/analysis/tests/TestRandomChains.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git
a/lucene/analysis/integration.tests/src/test/org/apache/lucene/analysis/tests/TestRandomChains.java
b/lucene/analysis/integration.tests/src/test/org/apache/lucene/analysis/tests/TestRandomChains.java
index acc8aeffbcb..4cc8e2d92fa 100644
---
a/lucene/analysis/integration.tests/src/test/org/apache/lucene/analysis/tests/TestRandomChains.java
+++
b/lucene/analysis/integration.tests/src/test/org/apache/lucene/analysis/tests/TestRandomChains.java
@@ -642,6 +642,10 @@ public class TestRandomChains extends
BaseTokenStreamTestCase {
@SuppressWarnings("unchecked")
static <T> T newRandomArg(Random random, Class<T> paramType) {
+ // if the argument type is not a primitive, return 1/10th of all cases
null:
+ if (!paramType.isPrimitive() && random.nextInt(10) == 0) {
+ return null;
+ }
final Function<Random, Object> producer = argProducers.get(paramType);
assertNotNull("No producer for arguments of type " + paramType.getName() +
" found", producer);
return (T) producer.apply(random);
@@ -750,7 +754,8 @@ public class TestRandomChains extends
BaseTokenStreamTestCase {
} catch (InvocationTargetException ite) {
final Throwable cause = ite.getCause();
if (cause instanceof IllegalArgumentException
- || cause instanceof UnsupportedOperationException) {
+ || cause instanceof UnsupportedOperationException
+ || cause instanceof NullPointerException) {
// thats ok, ignore
if (VERBOSE) {
System.err.println("Ignoring IAE/UOE from ctor:");
{noformat}
> Add null injection to analyzer integration tests (e.g. TestRandomChains)
> ------------------------------------------------------------------------
>
> Key: LUCENE-10353
> URL: https://issues.apache.org/jira/browse/LUCENE-10353
> Project: Lucene - Core
> Issue Type: Task
> Reporter: Robert Muir
> Priority: Major
>
> These tests inject random parameter values (from argumentProviders). Some
> generated values may be illegal and IllegalArgumentException is "allowed" if
> the constructor returns it. None of the values should cause failures at
> runtime.
> But for object types, we never inject null values (unless the
> argumentProvider were to do it itself). We should do this some low % of the
> time, and "allow" ctors to return NPE too.
> I see bugs in some of the analyzers where they are just a missing null check
> in the constructor. It is important to fail on invalid configuration up-front
> in the ctor, rather than failing e.g. at index time.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]