Skip to content

Fix parsing when an artifact id is a Maven scope/type keyword#110

Open
soutaro wants to merge 1 commit into
jruby:masterfrom
soutaro:claude/jar-dependencies-keyword-bug-arm3ai
Open

Fix parsing when an artifact id is a Maven scope/type keyword#110
soutaro wants to merge 1 commit into
jruby:masterfrom
soutaro:claude/jar-dependencies-keyword-bug-arm3ai

Conversation

@soutaro

@soutaro soutaro commented Jul 15, 2026

Copy link
Copy Markdown

Jars::Installer::Dependency generated a broken require_jar line for any artifact whose artifact id equals a Maven scope/type keyword (runtime, compile, test, provided, system, jar, pom).

For com.dylibso.chicory:runtime it produced:

require_jar 'com.dylibso.chicory', 'jar', '1.7.5'      # Wrong

require_jar 'com.dylibso.chicory', 'runtime', '1.7.5'  # Expected

The generated *_jars.rb then failed at runtime with LoadError: cannot load such file -- com/dylibso/chicory/jar/1.7.5/jar-1.7.5.jar, breaking any gem that depends on such a jar (e.g. com.dylibso.chicory:runtime).

Root cause

A dependency:list line has the form:

groupId:artifactId:type[:classifier]:version:scope:/path/to/file ​

Several fields were located by matching a keyword against the whole line:

  • @gav = @coord.sub(REG, ':'), where REG also lists the scope keywords, so String#sub replaced the leftmost match — the artifact id (:runtime:) — instead of the type separator (:jar:).
  • scope and the system? flag were derived from case line when /:test:/ … and line.index(':system:'), which matched a keyword artifact id rather than the real scope field.

Because sub/index match the leftmost occurrence, any artifact id that happens to be a keyword corrupts the result.

Fix

Parse positionally instead of by keyword matching:

  1. Peel off the trailing file path first (it may itself contain a : on Windows, C:\…) with a single match on TRAILING_FILE.
  2. The remainder is colon-clean, so split it once and address every field by position: type is field 3, version is last, an extra field between them is the classifier, scope is last.
  3. Rebuild coord/gav from those parts.

This removes the keyword regexes entirely and also fixes the case where the artifact id equals the type itself (jar/pom).

A dependency:list line is
  groupId:artifactId:type[:classifier]:version:scope:/path/to/file
Fields were located by matching a keyword against the whole line, which
picks the wrong colon when the artifact id itself equals a scope/type
keyword (runtime, compile, test, provided, system, jar, pom). For
com.dylibso.chicory:runtime the gav became com.dylibso.chicory:jar:1.7.5,
producing a broken require_jar line (LoadError at runtime); the scope and
system flag were likewise misdetected.

Peel off the trailing file path first (it may contain a ':' on Windows,
C:\...) via a single match, then split the remaining colon-clean
coordinate once and address every field by position: type is field 3,
version is last, an extra field between them is the classifier, scope is
last. gav and coord are rebuilt from those parts. This removes the
keyword regexes entirely and also handles an artifact id equal to the
type itself.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@kares kares left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid bug and the fix seems to work (tests pass), thank you Soutaro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants