From ebe372a18b5887ca393f0f7ff2410ee95db09eac Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Sun, 4 Oct 2026 01:36:14 -0400 Subject: [PATCH 1/5] SOLR-7498: do not add the text null as stream_size when the stream size is unknown Hypothetical, unrun regression test; see SOLR-7498-TESTING.md. --- .../handler/extraction/ExtractionBackend.java | 5 +- .../ExtractionBackendMetadataTest.java | 63 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractionBackendMetadataTest.java diff --git a/solr/modules/extraction/src/java/org/apache/solr/handler/extraction/ExtractionBackend.java b/solr/modules/extraction/src/java/org/apache/solr/handler/extraction/ExtractionBackend.java index 1b30dbb3385f..a170c77075f4 100644 --- a/solr/modules/extraction/src/java/org/apache/solr/handler/extraction/ExtractionBackend.java +++ b/solr/modules/extraction/src/java/org/apache/solr/handler/extraction/ExtractionBackend.java @@ -52,7 +52,10 @@ default ExtractionMetadata buildMetadataFromRequest(ExtractionRequest request) { md.add(ExtractingMetadataConstants.HTTP_HEADER_CONTENT_TYPE, request.contentType); md.add(ExtractingMetadataConstants.STREAM_NAME, request.streamName); md.add(ExtractingMetadataConstants.STREAM_SOURCE_INFO, request.streamSourceInfo); - md.add(ExtractingMetadataConstants.STREAM_SIZE, String.valueOf(request.streamSize)); + // the size is unknown (null) for streams that do not report one; do not add the text "null" + if (request.streamSize != null) { + md.add(ExtractingMetadataConstants.STREAM_SIZE, String.valueOf(request.streamSize)); + } md.add(ExtractingMetadataConstants.STREAM_CONTENT_TYPE, request.contentType); md.add(ExtractingMetadataConstants.HTTP_HEADER_CONTENT_ENCODING, request.charset); return md; diff --git a/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractionBackendMetadataTest.java b/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractionBackendMetadataTest.java new file mode 100644 index 000000000000..391d226c41e8 --- /dev/null +++ b/solr/modules/extraction/src/test/org/apache/solr/handler/extraction/ExtractionBackendMetadataTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.handler.extraction; + +import java.io.InputStream; +import org.apache.solr.SolrTestCase; +import org.junit.Test; +import org.xml.sax.helpers.DefaultHandler; + +/** SOLR-7498: an unknown stream size must not be reported as the text "null". */ +public class ExtractionBackendMetadataTest extends SolrTestCase { + + private static final ExtractionBackend BACKEND = + new ExtractionBackend() { + @Override + public ExtractionResult extract(InputStream inputStream, ExtractionRequest request) { + throw new UnsupportedOperationException(); + } + + @Override + public void extractWithSaxHandler( + InputStream inputStream, + ExtractionRequest request, + ExtractionMetadata md, + DefaultHandler saxContentHandler) { + throw new UnsupportedOperationException(); + } + + @Override + public String name() { + return "test"; + } + }; + + @Test + public void testUnknownStreamSizeIsNotAdded() { + ExtractionRequest request = ExtractionRequest.builder().streamName("doc.pdf").build(); + ExtractionMetadata md = BACKEND.buildMetadataFromRequest(request); + assertNull(md.getFirst(ExtractingMetadataConstants.STREAM_SIZE)); + assertEquals("doc.pdf", md.getFirst(ExtractingMetadataConstants.STREAM_NAME)); + } + + @Test + public void testKnownStreamSizeIsAdded() { + ExtractionRequest request = ExtractionRequest.builder().streamSize(1234L).build(); + ExtractionMetadata md = BACKEND.buildMetadataFromRequest(request); + assertEquals("1234", md.getFirst(ExtractingMetadataConstants.STREAM_SIZE)); + } +} From 67a79ce7d9ecffee71b9a7c7ec42bf369469b0d7 Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Sun, 4 Oct 2026 01:36:15 -0400 Subject: [PATCH 2/5] SOLR-7498: add changelog fragment --- .../unreleased/SOLR-7498-extract-null-stream-size.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 changelog/unreleased/SOLR-7498-extract-null-stream-size.yml diff --git a/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml b/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml new file mode 100644 index 000000000000..4f7d3d5db437 --- /dev/null +++ b/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml @@ -0,0 +1,10 @@ +title: > + The extracting request handler no longer indexes the text "null" as stream_size when the size of + the uploaded content stream is unknown, which failed on numeric stream_size fields. +type: fixed +authors: + - name: Nick Shanin + nick: nick-boss-tech +links: + - name: SOLR-7498 + url: https://issues.apache.org/jira/browse/SOLR-7498 From 40fd1e632522ede9fcf1f897b4578f9dcca1ab31 Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Sun, 4 Oct 2026 01:36:17 -0400 Subject: [PATCH 3/5] SOLR-7498: add hypothetical-reproduction handoff doc --- SOLR-7498-TESTING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SOLR-7498-TESTING.md diff --git a/SOLR-7498-TESTING.md b/SOLR-7498-TESTING.md new file mode 100644 index 000000000000..52499a44be8f --- /dev/null +++ b/SOLR-7498-TESTING.md @@ -0,0 +1,29 @@ +# SOLR-7498 - hypothetical-reproduction handoff + +**Read this first: nothing on this branch was compiled or run.** The research/implement pipeline has no Gradle access. The fix and test are best-guess; treat them as hypotheses. + +- JIRA: https://issues.apache.org/jira/browse/SOLR-7498 - "Error adding field 'stream_size'='null' msg=For input string: "null" using ContentStreamUpdateRequest" (Swoorup Joshi). A later comment reports the same with SolrJ 8.11.1; `bin/post` works because it sets a numeric size. +- Branch: `solr-7498-submit` off `apache/solr` main `14c7aac0d15` +- Commits: fix + test, changelog fragment, this file (drop the doc before a PR) + +## The bug, as understood +`ExtractionBackend.buildMetadataFromRequest` does `md.add(STREAM_SIZE, String.valueOf(request.streamSize))`. `streamSize` is a `Long` that is `null` when the content stream does not report a size (`ContentStream.getSize()` returns null, e.g. SolrJ `ContentStreamUpdateRequest` with a streamed body). `String.valueOf((Object) null)` is the text `"null"`, which then maps to the `stream_size` field and fails for numeric types. Still true on main (`ExtractionBackend.java` L55). + +## What the branch changes +- `ExtractionBackend.buildMetadataFromRequest`: only add `stream_size` when the size is known (`ExtractionMetadata.add` already ignores null values). +- New `ExtractionBackendMetadataTest` (plain `SolrTestCase`, anonymous backend stub): unknown size gives no `stream_size`; `1234L` gives `"1234"`. + +## What was guessed (verify these first) +1. `ExtractionBackend` has exactly the abstract methods stubbed in the test (`extract`, `extractWithSaxHandler`, `name`); a newer abstract method would break compilation. `ExtractionResult` is assumed to be a type in the same package. +2. `ExtractionRequest.builder()` accepts a missing size and `STREAM_NAME` is a constant in `ExtractingMetadataConstants`. +3. Whether other consumers of `stream_size` metadata rely on the `"null"` text (none found in the module). + +## How to verify (Gradle required; not run here) +``` +.\gradlew :solr:modules:extraction:spotlessApply +.\gradlew :solr:modules:extraction:test --tests "org.apache.solr.handler.extraction.ExtractionBackendMetadataTest" +``` +Fail-before: revert only `ExtractionBackend.java`; `getFirst(STREAM_SIZE)` returns `"null"`. + +## Not done +No JIRA comment, no PR. Changelog author is `Nick Shanin` per the ICLA note. From ecd9271d8a4b0aea143c561e7313685136b82cd2 Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Sun, 4 Oct 2026 23:15:40 +0000 Subject: [PATCH 4/5] SOLR-7498: fix the changelog author entry --- changelog/unreleased/SOLR-7498-extract-null-stream-size.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml b/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml index 4f7d3d5db437..856363d468fc 100644 --- a/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml +++ b/changelog/unreleased/SOLR-7498-extract-null-stream-size.yml @@ -4,7 +4,6 @@ title: > type: fixed authors: - name: Nick Shanin - nick: nick-boss-tech links: - name: SOLR-7498 url: https://issues.apache.org/jira/browse/SOLR-7498 From 2050d8e447a733966d5f6e4742a1a8ea931a2b00 Mon Sep 17 00:00:00 2001 From: Nick Shanin Date: Mon, 5 Oct 2026 09:54:54 +0000 Subject: [PATCH 5/5] SOLR-7498: remove the hypothetical-reproduction handoff doc before submission --- SOLR-7498-TESTING.md | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 SOLR-7498-TESTING.md diff --git a/SOLR-7498-TESTING.md b/SOLR-7498-TESTING.md deleted file mode 100644 index 52499a44be8f..000000000000 --- a/SOLR-7498-TESTING.md +++ /dev/null @@ -1,29 +0,0 @@ -# SOLR-7498 - hypothetical-reproduction handoff - -**Read this first: nothing on this branch was compiled or run.** The research/implement pipeline has no Gradle access. The fix and test are best-guess; treat them as hypotheses. - -- JIRA: https://issues.apache.org/jira/browse/SOLR-7498 - "Error adding field 'stream_size'='null' msg=For input string: "null" using ContentStreamUpdateRequest" (Swoorup Joshi). A later comment reports the same with SolrJ 8.11.1; `bin/post` works because it sets a numeric size. -- Branch: `solr-7498-submit` off `apache/solr` main `14c7aac0d15` -- Commits: fix + test, changelog fragment, this file (drop the doc before a PR) - -## The bug, as understood -`ExtractionBackend.buildMetadataFromRequest` does `md.add(STREAM_SIZE, String.valueOf(request.streamSize))`. `streamSize` is a `Long` that is `null` when the content stream does not report a size (`ContentStream.getSize()` returns null, e.g. SolrJ `ContentStreamUpdateRequest` with a streamed body). `String.valueOf((Object) null)` is the text `"null"`, which then maps to the `stream_size` field and fails for numeric types. Still true on main (`ExtractionBackend.java` L55). - -## What the branch changes -- `ExtractionBackend.buildMetadataFromRequest`: only add `stream_size` when the size is known (`ExtractionMetadata.add` already ignores null values). -- New `ExtractionBackendMetadataTest` (plain `SolrTestCase`, anonymous backend stub): unknown size gives no `stream_size`; `1234L` gives `"1234"`. - -## What was guessed (verify these first) -1. `ExtractionBackend` has exactly the abstract methods stubbed in the test (`extract`, `extractWithSaxHandler`, `name`); a newer abstract method would break compilation. `ExtractionResult` is assumed to be a type in the same package. -2. `ExtractionRequest.builder()` accepts a missing size and `STREAM_NAME` is a constant in `ExtractingMetadataConstants`. -3. Whether other consumers of `stream_size` metadata rely on the `"null"` text (none found in the module). - -## How to verify (Gradle required; not run here) -``` -.\gradlew :solr:modules:extraction:spotlessApply -.\gradlew :solr:modules:extraction:test --tests "org.apache.solr.handler.extraction.ExtractionBackendMetadataTest" -``` -Fail-before: revert only `ExtractionBackend.java`; `getFirst(STREAM_SIZE)` returns `"null"`. - -## Not done -No JIRA comment, no PR. Changelog author is `Nick Shanin` per the ICLA note.