Skip to content

Read Spoon compliance level from the project's pom.xml - #352

Merged
CatarinaGamboa merged 3 commits into
mainfrom
fix/compliance-level
Oct 7, 2026
Merged

CatarinaGamboa merged 3 commits into
mainfrom
fix/compliance-level

Conversation

@CatarinaGamboa

@CatarinaGamboa CatarinaGamboa commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

CommandLineLauncher sets Spoon's compliance level to 8, so any Java 9+ syntax fails to compile and LiquidJava verifies a broken model with only a generic warning ("Java compilation encountered issues"). E.g. var n = 5; is read as a variable of class testSuite.var (Sorts testSuite.var and Int are incompatible), and try (r) (Java 9 resource reference) does not parse, which blocks the second reproducer of #334.

Change

  • New ComplianceLevel reads the level from the maven.compiler.release (or maven.compiler.source) property of the nearest pom.xml of each verified path, walking up to enclosing poms, using the existing maven-model dependency. 1.8 is read as 8; with several paths the highest level wins.
  • Defaults to 19 when no pom declares it, and caps at 19: the highest level Spoon 10.4.2's JDT (3.33) accepts (20 throws Unrecognized option : -20). The cap is silent (the level is printed with --debug), since e.g. liquidjava-example declares 20 and a warning would show up on every run.
  • New test CorrectModernJavaSyntax (var, try (r), switch expression): fails at level 8, passes now.
  • Unit tests TestComplianceLevel (reads the pom, caps).

Not read (falls back to 19): the compiler plugin's <release>/<source> config, parents outside the enclosing directories, Gradle builds. Upgrading to Spoon 11.5 (levels up to 26) is in #363.

Testing

mvn test: 369/369 pass.

🤖 Generated with Claude Code

At level 8, Java 9+ syntax (`var`, `try (r)`, switch expressions) fails to
compile, so verification runs on a broken model (e.g. `var` becomes a class
`testSuite.var`). 17 is the highest level Spoon 10.4.2's JDT accepts.

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

alcides commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Should this be a cli flag? or read from maven?

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

I can check that but im not sure if all versions are supported by spoon

Spoon's compliance level is now taken from the nearest pom.xml of the
verified paths (compiler plugin release/source, then the
maven.compiler.release/source properties, walking up to enclosing poms).
It defaults to 19 when no pom declares one and is capped at 19, the
highest level Spoon 10.4.2's JDT accepts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CatarinaGamboa CatarinaGamboa added the dependencies Pull requests that update a dependency file label Oct 7, 2026
@CatarinaGamboa CatarinaGamboa changed the title Raise Spoon compliance level from 8 to 17 Read Spoon compliance level from the project's pom.xml Oct 7, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@rcosta358 rcosta358 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm. Won't work for Gradle projects but that can be done in a separate PR.

@CatarinaGamboa
CatarinaGamboa added this pull request to stack #365 October 7, 2026 11:33
@CatarinaGamboa
CatarinaGamboa merged commit e054c42 into main Oct 7, 2026
1 check passed
CatarinaGamboa added a commit that referenced this pull request Oct 7, 2026
Fixes #334. **Stacked on #352** (compliance level 17, needed to parse
`try (r)`); retarget to `main` once #352 merges.

## Problem
The `close()` Java inserts at the end of a try-with-resources block was
never checked, so a double close or a use after the block passed
verification.

## Change
`RefinementTypeChecker#visitCtTryWithResource` scans resources → body →
a synthesized `r.close()` per resource (reverse declaration order, as
Java does) → catchers → finally. The close goes through the normal
invocation check, so it works for both `@StateRefinement` classes and
external refinements.

Errors are reported at the resource declaration (`Res r = new Res()`).
For a Java 9 resource reference they're reported at the `try (r)`
header.

**Spoon workaround:** Spoon 10.4.2 models `try (r)` as an *implicit*
copy of `r`'s declaration, initializer included. It is also repeated
once per earlier local named `r` in the file, so `try (r)` can yield
`[r, r, r]`. Scanning those would re-run `new Res()` and reset the
state, so implicit resources are not scanned and are closed once per
name.

## Tests
- `classes/try_with_resources_error`: double close (both reproducers
from #334), use after the block, use in `catch`, and `try (r)` on an
already-closed `r`.
- `classes/try_with_resources_correct`: use inside, multiple resources,
`try (r)`, catch + finally.

`mvn test`: 369/369 pass.

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
CatarinaGamboa added a commit that referenced this pull request Oct 7, 2026
Follow-up to #352 (stacked on it; GitHub will retarget to `main` once
#352 merges).

## Problem
Spoon 10.4.2 bundles JDT 3.33, which only accepts compliance levels up
to 19 (`20` throws `Unrecognized option : -20`), so #352 has to cap the
level read from the project's pom at 19.

## Change
- `version.spoon`: 10.4.2 → **11.5.0** (JDT 3.46). It needs a Java 17+
runtime (class files are Java 17), which is fine since the verifier
already targets 20.
- `ComplianceLevel.MAX_SUPPORTED` (and so the default when no pom
declares a version): 19 → **26**, the highest level JDT 3.46 accepts
(`27` throws).

No source changes were needed for the Spoon API.

## Downstream
`vscode-liquidjava/server/pom.xml` declares `spoon-core` directly with
`version.spoon` = 10.4.2. That direct dependency overrides the
verifier's transitive one, so the server should be bumped to 11.5.0
together with the verifier version that includes this change. Otherwise
projects declaring Java 20+ would make the model builder throw there.

## Testing
`mvn test`: 369/369 pass (same as #352).

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
CatarinaGamboa added a commit that referenced this pull request Oct 8, 2026
Redoes #363, which was merged into `fix/compliance-level` after that
branch had already been merged into `main` (#352), so `main` is still on
Spoon 10.4.2.

## Change
- `version.spoon`: 10.4.2 → **11.5.0** (JDT 3.46). Its class files
target Java 17, so it runs on our Java 20 build.
- `ComplianceLevel`: the cap goes from 19 to **26** (highest level JDT
3.46 accepts; `27` throws), and a separate `DEFAULT` of **21** is used
when no pom declares a Java version (it used to be the cap).
- `RefinementTypeChecker#visitCtTryWithResource` (from #358): in Spoon
11, `CtResource` is no longer a `CtVariable`. A resource is now either a
`CtLocalVariable` (`try (R r = ...)`) or a `CtVariableRead` (Java 9 `try
(r)`). Spoon 10 modelled `try (r)` as an implicit copy of `r`'s
declaration, repeated per earlier same-named local. That workaround
(skip implicit copies, dedupe by name, header position) is gone: every
resource is scanned and closed once, and the implicit `close()` is built
from the declaration's reference or a clone of the read, positioned at
the resource.

## Downstream
`vscode-liquidjava/server/pom.xml` declares `spoon-core` 10.4.2
directly, which overrides the verifier's version. Bump it to 11.5.0
together with the verifier release that includes this.

## Testing
`mvn test`: 379/379 pass, including `try_with_resources_correct` /
`try_with_resources_error` (both resource forms) and
`CorrectModernJavaSyntax`.

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants