Skip to content

Use MavenReference for JavaParser and update to 3.27.0 - #159

Merged
paulirwin merged 1 commit into
masterfrom
feature/117-maven-javaparser
Aug 16, 2026
Merged

Use MavenReference for JavaParser and update to 3.27.0#159
paulirwin merged 1 commit into
masterfrom
feature/117-maven-javaparser

Conversation

@paulirwin

Copy link
Copy Markdown
Owner

Fixes #117.

Replaces the vendored javaparser-core-3.25.4.jar with an IKVM MavenReference that resolves javaparser-core from Maven Central at build time, and updates 3.25.4 → 3.27.0 (latest).

Changes

  • Add IKVM.Maven.Sdk 1.12.0 to JavaToCSharp — this is the package that provides MavenReference; the IKVM package alone doesn't.
  • Swap IkvmReference for MavenReference on com.github.javaparser:javaparser-core.
  • Delete Lib/javaparser-core-3.25.4.jar (the Lib/ directory is now gone).
  • Drop the test project's duplicate IkvmReference and its IKVM package reference — both were only there to build the jar locally, and now come transitively via the project reference.
  • One README line, which described IKVM converting "the javaparser .jar" as if it were checked in.

Version note

3.27.0 is the latest, a few releases past the 3.26.1 suggested in the issue. It required no source changes — clean build, 0 warnings — so the upgrade is API-compatible for the surface this project uses. Verified the generated com.github.javaparser.core.dll actually carries 3.27.0 rather than trusting the restore.

javaparser-core-serialization from the issue's snippet is intentionally omitted — nothing in the codebase uses it.

Testing

  • Clean build from scratch (all bin/obj wiped), 0 warnings, 0 errors.
  • Confirmed the IKVM-generated assembly lands in both the library and test output, so transitive resolution works at runtime and not just at compile time.
  • 284/284 tests pass, across 6 consecutive runs.

Unrelated pre-existing issue found while verifying

While testing I hit generated output containing public static voidvoid Main (return type emitted twice). That looked like a 3.27.0 regression, so I checked: it reproduces on unmodified master at 3.25.4 (~1 run in 10) and is unrelated to this PR.

The cause is TypeNameParser holding its entire recursive-descent parse state — including a shared StringBuilder — in static fields, so parallel conversions splice each other's output. This means the library is not safe to call concurrently. Being fixed separately.

🤖 Generated with Claude Code

Replace the vendored javaparser-core-3.25.4.jar with an IKVM
MavenReference that resolves javaparser-core from Maven Central at
build time, and update from 3.25.4 to 3.27.0 (latest).

- Add IKVM.Maven.Sdk package reference to JavaToCSharp
- Swap IkvmReference for MavenReference on com.github.javaparser:javaparser-core
- Delete Lib/javaparser-core-3.25.4.jar from the repo
- Drop the test project's duplicate IkvmReference and IKVM package
  reference; both now come transitively via the project reference

No source changes were needed, so the 3.25.4 -> 3.27.0 upgrade is
API-compatible for the surface this project uses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@paulirwin
paulirwin merged commit c8e02f8 into master Aug 16, 2026
6 of 7 checks passed
@paulirwin
paulirwin deleted the feature/117-maven-javaparser branch August 16, 2026 02:05
paulirwin added a commit that referenced this pull request Aug 16, 2026
Fixes the intermittent test failures noted in #159.

`JavaToCSharp` was not safe to call concurrently. This affects real
consumers converting files in parallel, and it was also causing flaky
CI: roughly 1 run in 10 failed, in a *different* test class each time.

## The bug

`TypeNameParser` was a `static` class holding its **entire
recursive-descent parse state** in static fields — including a shared
`StringBuilder`:

```csharp
private static (string, TokenType)[]? _tokens;
private static (string text, TokenType type) _token;
private static int _currentIndex;
private static readonly StringBuilder _sb = new();
```

`ConvertType` is on the hot path of essentially every conversion, and
xUnit runs test classes in parallel. Two conversions interleaving
`_sb.Clear()` / `_sb.Append()` splice each other's output — the symptom
that led me here was generated code containing:

```csharp
public static voidvoid Main(string[] args)
```

The return type emitted twice. Concurrent mutation of the shared token
array and index can also throw `IndexOutOfRangeException` outright,
which is what the new test hits first against the old code.

## The fix

- **`TypeNameParser` is now an instance class**, constructed fresh per
`ParseTypeName` call, so no parse state is shared. The public entry
point is unchanged — this is not a breaking change.
- **`TypeHelper._typeNameConversions` is now a `ConcurrentDictionary`.**
It's mutated during conversion by `ClassOrInterfaceDeclarationVisitor`
(registering interface renames when `StartInterfaceNamesWithI` is set)
while other threads read it in `ConvertType` — undefined behavior for
`Dictionary<,>`.
- Dropped two now-dead defensive checks: `_tokens` is always assigned in
the constructor, and `_translate?.Invoke(...)` was silently appending an
empty string on null rather than failing.

## Testing

New `ConcurrencyTests` covers parallel `ConvertType` calls and parallel
end-to-end conversions. I verified these are genuine regression tests:
**both fail reliably against the old code** (stashed the fix and
confirmed) and pass with it.

Full suite run **15 consecutive times: 286/286 passing every time**. On
`master` the same loop reproduces a failure within ~10 runs.

## Note on scope

`TypeHelper._typeNameConversions` being process-global mutable state is
still a design smell — per-file class renames leak between conversions,
so converting two files with `StartInterfaceNamesWithI` can bleed one
file's renames into the other. The proper fix is moving it onto
`ConversionContext`, but `ConvertType` has ~60 call sites and is public
API used directly by tests, so that's a larger breaking change. This PR
makes it *safe* without changing the API; happy to do the deeper
refactor separately if you want it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

Use ikvm maven to use the latest JavaParser

1 participant