Uploaded image for project: 'Dev - Nexus Repo'
  1. Dev - Nexus Repo
  2. NEXUS-30537

Repair - Rebuild repository search task fails with "java.lang.StringIndexOutOfBoundsException: String index out of range: 0"

    Details

    • Story Points:
      2
    • Sprint:
      NXRM Immortals Sprint 30
    • Notability:
      3
    • InvestmentLayer:
      customer-driven
    • Aha Concept:
      non-concept

      Description

       SYMPTOM:

      After upgrading to 3.37, the Repair - Rebuild repository search task started failing with below ERROR:

      2022-03-28 17:50:31,323+0000 ERROR [quartz-21-thread-19]  *SYSTEM org.sonatype.nexus.repository.search.SearchFacetImpl - Unable to rebuild search index for repository repo-latest
      java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      	at java.lang.String.charAt(String.java:658)
      	at org.sonatype.nexus.repository.maven.internal.search.MavenVersionNormalizer.getQualifierType(MavenVersionNormalizer.java:222)
      	at org.sonatype.nexus.repository.maven.internal.search.MavenVersionNormalizer.getNormalizedValue(MavenVersionNormalizer.java:231)
      	at org.sonatype.nexus.repository.maven.internal.search.MavenVersionNormalizer.getNormalizedValue(MavenVersionNormalizer.java:124)
      	at org.sonatype.nexus.repository.maven.internal.orient.Maven2ComponentMetadataProducer.getNormalizedVersion(Maven2ComponentMetadataProducer.java:63)
      	at org.sonatype.nexus.repository.search.DefaultComponentMetadataProducer.getMetadata(DefaultComponentMetadataProducer.java:112)
      	at org.sonatype.nexus.repository.search.SearchFacetImpl.json(SearchFacetImpl.java:251)
      	at org.sonatype.nexus.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:49)
      	at org.sonatype.nexus.repository.search.index.SearchIndexServiceImpl.lambda$0(SearchIndexServiceImpl.java:300)
      	at java.util.ArrayList.forEach(ArrayList.java:1259)
      	at org.sonatype.nexus.repository.search.index.SearchIndexServiceImpl.bulkPut(SearchIndexServiceImpl.java:297)
      	at org.sonatype.nexus.repository.search.SearchFacetImpl.bulkPut(SearchFacetImpl.java:182)
      	at org.sonatype.nexus.common.stateguard.MethodInvocationAction.run(MethodInvocationAction.java:39)
      	at org.sonatype.nexus.common.stateguard.StateGuard$GuardImpl.run(StateGuard.java:272)
      	at org.sonatype.nexus.common.stateguard.GuardedInterceptor.invoke(GuardedInterceptor.java:54)
      	at org.sonatype.nexus.repository.search.SearchFacetImpl.rebuildComponentIndex(SearchFacetImpl.java:152)
      	at org.sonatype.nexus.transaction.TransactionalWrapper.proceedWithTransaction(TransactionalWrapper.java:58)
      	at org.sonatype.nexus.transaction.TransactionInterceptor.proceedWithTransaction(TransactionInterceptor.java:66)
      	at org.sonatype.nexus.transaction.TransactionInterceptor.invoke(TransactionInterceptor.java:55)
      	at org.sonatype.nexus.repository.search.SearchFacetImpl.rebuildIndex(SearchFacetImpl.java:115)
      	at org.sonatype.nexus.common.stateguard.MethodInvocationAction.run(MethodInvocationAction.java:39)
      	at org.sonatype.nexus.common.stateguard.StateGuard$GuardImpl.run(StateGuard.java:272)
      	at org.sonatype.nexus.common.stateguard.GuardedInterceptor.invoke(GuardedInterceptor.java:54)
      	at org.sonatype.nexus.repository.search.index.RebuildIndexTask.execute(RebuildIndexTask.java:33)
      	at org.sonatype.nexus.repository.RepositoryTaskSupport.execute(RepositoryTaskSupport.java:79)
      	at org.sonatype.nexus.scheduling.TaskSupport.call(TaskSupport.java:100)
      	at org.sonatype.nexus.quartz.internal.task.QuartzTaskJob.doExecute(QuartzTaskJob.java:143)
      	at org.sonatype.nexus.quartz.internal.task.QuartzTaskJob.execute(QuartzTaskJob.java:106)
      	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
      	at org.sonatype.nexus.quartz.internal.QuartzThreadPool.lambda$0(QuartzThreadPool.java:145)
      	at org.sonatype.nexus.thread.internal.MDCAwareRunnable.run(MDCAwareRunnable.java:40)
      	at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120)
      	at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      

      REPRODUCE STEPS:

      1. Install a new NXRM 3.37.0
      2. Deploy some app which has the version string ends with "-". For example:
        <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
          <modelVersion>4.0.0</modelVersion>
          <groupId>com.example</groupId>
          <artifactId>my-app</artifactId>
          <packaging>jar</packaging>
          <version>1.0-</version>
          <name>my-app</name>
        ...
        
      1. Schedule and run the Repair - Rebuild repository search task

      EXPECTED BEHAVIOUR:

      Not sure if the version ending or starting with "-" is the valid but as Nexus does not refuse, the task should complete without any error.

      If the rebuild search task fails processing a single asset/component for ANY reason, log that reason and try to process the rest of the components. Do not fail the task just because one parsing error.

      If there is an error, log as much as we know about what component failed ( group id, artifact id, etc. ) . See NEXUS-31500.

      POTENTIAL CAUSE:

      NEXUS-28918 added org.sonatype.nexus.repository.maven.internal.search.MavenVersionNormalizer#splitQualifier, and this one can return the empty string "" when the version ends with "-":

      jshell> splitQualifier("aaaa")
      $2 ==> String[2] { "", "aaaa" }
      
      jshell> splitQualifier("1-")
      $3 ==> String[2] { "1", "" }
      
      jshell> splitQualifier("-TEST")
      $4 ==> String[2] { "", "TEST" }
      

      So that org.sonatype.nexus.repository.maven.internal.search.MavenVersionNormalizer#getQualifierType could cause this Exception when it tries to get the first char from the empty string.

      Patch for Nexus Repo 3.38.1-01

      A patch which fixes this issue for Nexus Repo 3.38.1-01 can be found here: NEXUS-30537-3.38.1-01-patch.zip.   This patch is only for that version, it will not work in other versions.   To apply this patch unzip the attached file in the "nexus-3.38.1-01" directory.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mpiggott Matthew Piggott
              Reporter:
              hosako Hajime Osako
              Last Updated By:
              Michael Prescott Michael Prescott
              Team:
              NXRM - Neo
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Date of First Response:

                  tigCommentSecurity.panel-title