apache / apache/lucene

Unit tests using StringHelper fail with ExceptionInInitializerError for maven surefire >= 2.18 [LUCENE-8146]

Open
#9,194 15 comments 0 reactions 0 assignees View on GitHub
affects-version:7.2.1 legacy-jira-priority:Minor type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

This happens when multiple conditions are met:
- The client code is built with Maven
- To execute its unit tests, the client code relies on the `maven-surefire-plugin`, with a version greater than 2.17 (last working version)
- The client code uses the `org.apache.lucene.util.StringHelper` class (even transitively)
- The client is configured as with the standard Lucene maven build (i.e. it is possible to fix the test seed using the `tests.seed` property)

There was a change in Surefire's behavior starting with 2.18: when a property is empty, instead of not sending it to the test runner, it will be sent with an empty value.

This behavior can be observed with the attached sample project:
- `mvn test`: fails with a `java.lang.ExceptionInInitializerError`
- `mvn test -Dtests.seed=123456`: succeeds because the property is set to a real value
- `mvn test -Dsurefire.version=2.17`: succeeds because the surefire version is lower than 2.18

Attached is a patch (built against \`branch_7x`) that centralizes accesses to the `tests.seed` system property; it also makes sure that if it is empty, it is treated as absent.

---
Migrated from [LUCENE-8146](https://issues.apache.org/jira/browse/LUCENE-8146) by Julien Massenet, updated Apr 15 2019
Attachments: [LUCENE-8146_v1.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8146/LUCENE-8146_v1.patch), [LUCENE-8146_v2.patch](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8146/LUCENE-8146_v2.patch), [LUCENE-8146-seed_issue.tar.gz](https://apache.github.io/lucene-jira-archive/attachments/LUCENE-8146/LUCENE-8146-seed_issue.tar.gz)
Linked issues:
- [SUREFIRE-649](https://issues.apache.org/jira/browse/SUREFIRE-649)

Contributor guide

Open the contributing guide

Research direction

Start with org.apache.lucene.util.StringHelper and the tests.seed system property, then reproduce the attached sample with mvn test. Compare behavior with -Dtests.seed=123456 and surefire 2.17; done means empty tests.seed values no longer cause ExceptionInInitializerError while preserving fixed-seed tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.