Skip to content

StringIndexOutOfBoundsException exception from org.spdx.utility.compare.TemplateRegexMatcher.findTemplateWithinText() #242

Closed

Description

@pmonks

When calling org.spdx.utility.compare.LicenseCompareHelper.matchingStandardLicenseIdsWithinText(), I'm getting a StringIndexOutOfBoundsException thrown from within org.spdx.utility.compare.TemplateRegexMatcher.findTemplateWithinText() because the start index is larger than the end index. At this time I'm not sure exactly what the values of the arguments are to that method that are causing the issue, but I'll start trying to track that down next. This used to work with SPDX License List v3.23, so it's possible this is related to something that changed in SPDX License List v3.24.0.

The full exception stack trace is as follows, and note that the formatting may look unfamiliar as Clojure has its own way of printing exception stack traces:

{:clojure.main/message
 "Execution error (StringIndexOutOfBoundsException) at jdk.internal.util.Preconditions$1/apply (Preconditions.java:55).\nRange [18134, 17912) out of bounds for length 29880\n",
 :clojure.main/triage
 {:clojure.error/class java.lang.StringIndexOutOfBoundsException,
  :clojure.error/line 55,
  :clojure.error/cause
  "Range [18134, 17912) out of bounds for length 29880",
  :clojure.error/symbol jdk.internal.util.Preconditions$1/apply,
  :clojure.error/source "Preconditions.java",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type java.util.concurrent.ExecutionException,
    :message "java.util.concurrent.ExecutionException: java.lang.StringIndexOutOfBoundsException: Range [18134, 17912) out of bounds for length 29880",
    :at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
   {:type java.util.concurrent.ExecutionException,
    :message "java.lang.StringIndexOutOfBoundsException: Range [18134, 17912) out of bounds for length 29880",
    :at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
   {:type java.lang.StringIndexOutOfBoundsException,
    :message "Range [18134, 17912) out of bounds for length 29880",
    :at [jdk.internal.util.Preconditions$1 apply "Preconditions.java" 55]}],
  :trace
  [[jdk.internal.util.Preconditions$1 apply "Preconditions.java" 55]
   [jdk.internal.util.Preconditions$1 apply "Preconditions.java" 52]
   [jdk.internal.util.Preconditions$4 apply "Preconditions.java" 213]
   [jdk.internal.util.Preconditions$4 apply "Preconditions.java" 210]
   [jdk.internal.util.Preconditions outOfBounds "Preconditions.java" 98]
   [jdk.internal.util.Preconditions outOfBoundsCheckFromToIndex "Preconditions.java" 112]
   [jdk.internal.util.Preconditions checkFromToIndex "Preconditions.java" 349]
   [java.lang.String checkBoundsBeginEnd "String.java" 4865]
   [java.lang.String substring "String.java" 2834]
   [org.spdx.utility.compare.TemplateRegexMatcher findTemplateWithinText "TemplateRegexMatcher.java" 322]
   [org.spdx.utility.compare.TemplateRegexMatcher isTemplateMatchWithinText "TemplateRegexMatcher.java" 278]
   [org.spdx.utility.compare.LicenseCompareHelper isStandardLicenseWithinText "LicenseCompareHelper.java" 890]
   [org.spdx.utility.compare.LicenseCompareHelper matchingStandardLicenseIdsWithinText "LicenseCompareHelper.java" 959]
   [spdx.matching$licenses_within_text invokeStatic "matching.clj" 84]
   [spdx.matching$licenses_within_text invoke "matching.clj" 71]
   [lice_comb.impl.matching$eval23925$fn__23926$fn__23927 invoke "matching.clj" 136]
   [embroidery.api$pmap_STAR_$fn$reify__22819 call "vthreads.clj" 36]
   [java.util.concurrent.FutureTask run "FutureTask.java" 317]
   [java.lang.VirtualThread run "VirtualThread.java" 309]],
  :cause "Range [18134, 17912) out of bounds for length 29880"}}

Execution error (StringIndexOutOfBoundsException) at jdk.internal.util.Preconditions$1/apply (Preconditions.java:55).
Range [18134, 17912) out of bounds for length 29880

This was reproduced with Java v21.0.3+9, Spdx-Java-Library v1.1.11, and SPDX License List v3.24.0.

Activity

  1. goneall commented on Jun 5, 2024

    @goneall
    Member

    I did a quick look at the code and the out of bound is likely caused by an a substring range where the end is before the start.

    I can see a corner case where this can happen if the pattern searching for the end of the license happens to also match the pattern before the start of the license.

    We could add a check for this and look for a following match if this occurs.

    The code to be updated is in the findTemplateInText method.

  2. goneall commented on Feb 26, 2025

    @goneall
    Member

    @pmonks - Do you have some text that reproduces this?

  3. added a commit that references this issue on Feb 26, 2025
    f8adfe7
  4. added
    bugSomething isn't working
    on Feb 26, 2025
  5. pmonks commented on Mar 7, 2025

    @pmonks
    CollaboratorAuthor

    Hmmmm I can't find a test case for it in my usual set, and it's long enough ago now that I don't recall what it was that triggered it. I have a very vague memory that perhaps the problem had nothing to do with the input text though, and instead occurred when a license list v3.24.0 template was being "compiled" for the purposes of matching, that had previously worked in license list v3.23.0. Perhaps looking at what changed between those two versions of the license list would narrow down the potential culprits?

  6. goneall commented on Mar 7, 2025

    @goneall
    Member

    @pmonks - no worries - if you could review #299 - I'm about 90% sure this will fix the issue.

  7. added a commit that references this issue on Apr 4, 2025
    0906908
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmatchingLicense matching and recognition

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions