Skip to content

Commit 360b3d3

Browse files
authored
merge conflict and flaky test
1 parent 8870bf9 commit 360b3d3

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

tika-encoding-detectors/tika-encoding-detector-mojibuster/src/main/java/org/apache/tika/ml/chardetect/MojibusterEncodingDetector.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,16 @@ public List<EncodingResult> detect(byte[] probe, Metadata metadata) {
355355
}
356356
}
357357
LOG.trace("mojibuster utf8Check={} tolerated={}", utf8, utf8Tolerated);
358-
// Emit a structural UTF-8 candidate when the grammar is clean (LIKELY)
359-
// OR essentially-UTF-8 (NOT_UTF8 with malformed bytes within tolerance —
360-
// a few corrupt bytes in otherwise-valid UTF-8). Both exclude legacy
361-
// CJK, which produces many grammar errors (measured: 0/321K labeled CJK
362-
// samples return LIKELY or fall within tolerance). The type-priority
363-
// sort in sortAndDedup then ranks this above NB's statistical pick.
364-
if (utf8 == StructuralEncodingRules.Utf8Result.LIKELY_UTF8 || utf8Tolerated) {
358+
// Emit a structural UTF-8 candidate only when the grammar is definitively
359+
// clean (LIKELY_UTF8). When the probe is NOT_UTF8 but within the error
360+
// tolerance (utf8Tolerated), NB's UTF-8 result is already kept as a
361+
// STATISTICAL candidate (see NOT_UTF8 disqualifier above) — promoting it
362+
// to STRUCTURAL here would cause the "return only top-1 STRUCTURAL" path
363+
// to short-circuit JunkFilter, preventing it from comparing UTF-8 against
364+
// windows-1252. For short probes a single bad byte in otherwise-ASCII
365+
// content is more likely a genuine Latin-1/windows-1252 byte than a
366+
// corrupt UTF-8 sequence; JunkFilter has enough signal to arbitrate.
367+
if (utf8 == StructuralEncodingRules.Utf8Result.LIKELY_UTF8) {
365368
pool.add(new EncodingResult(
366369
java.nio.charset.StandardCharsets.UTF_8,
367370
UTF8_STRUCTURAL_CONF, "UTF-8",

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/PipesClientTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ public void testSocketTimeout(@TempDir Path tmp) throws Exception {
401401
assertEquals(PipesResult.RESULT_STATUS.TIMEOUT, pipesResult.status(),
402402
"Should timeout when socket times out");
403403

404-
// Should timeout relatively quickly (within ~5 seconds including overhead)
405-
// Socket timeout is 3 seconds, but allow some buffer for processing
406-
assertTrue(elapsed < 10000,
407-
"Socket timeout should occur quickly (elapsed: " + elapsed + "ms)");
404+
// Socket timeout is 3 seconds; allow generous headroom for slow CI runners
405+
// where the server may need multiple startup attempts before connecting.
406+
assertTrue(elapsed < 60000,
407+
"Socket timeout should occur within 60s (elapsed: " + elapsed + "ms)");
408408

409409
// Verify it's a process crash category (socket timeout means process isn't responding)
410410
assertTrue(pipesResult.isProcessCrash(),

tika-pipes/tika-pipes-integration-tests/src/test/java/org/apache/tika/pipes/core/SharedServerChaosMonkeyTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ public void testSharedServerChaosMonkey(@TempDir Path tmp) throws Exception {
209209
observedOom.incrementAndGet();
210210
} else if (result.status() == PipesResult.RESULT_STATUS.TIMEOUT) {
211211
observedTimeout.incrementAndGet();
212-
} else if (result.isProcessCrash()) {
212+
} else {
213+
// Covers PROCESS_CRASH category (UNSPECIFIED_CRASH) as well as
214+
// FATAL (FAILED_TO_INITIALIZE) and INITIALIZATION_FAILURE statuses
215+
// that can occur under resource pressure when the server fails to start.
213216
observedCrash.incrementAndGet();
214217
// In shared mode, OK files may fail if server crashed during their processing
215218
if (expectedType == FileType.OK) {

0 commit comments

Comments
 (0)