Skip to content

Fix javac lint warnings in KeY (deprecation, unchecked, rawtypes) - #4004

Open
wadoon wants to merge 25 commits into
mainfrom
weigl/cleanwarnings
Open

wadoon wants to merge 25 commits into
mainfrom
weigl/cleanwarnings

Conversation

@wadoon

@wadoon wadoon commented Oct 24, 2026 •

Copy link
Copy Markdown
Member

What

Cleanup of the KeY compiler-warning inventory — javac -Xlint:all lint warnings, plus the javadoc diagnostics — delivered as a single PR on one linear branch (the previous per-category gh stack has been abandoned; all cleanup work lives here now). The branch now sits directly on main (base 407f0f3cb6): the work was originally stacked on PR #4001 (weigl/rmimarray) and is now rebased onto main — 25 commits (313 files changed, +2043/−656). Main has in the meantime deprecated ImmutableArray in favor of ImmutableList while the large majority of call sites still use the former; the rebase's conflict resolutions keep main's types and apply the warning fixes on top of them (the pre-rebase head is preserved in backup/pre-rebase-4004).

Javac lint cleanup — enable all lint warnings in the shared JavaCompile configuration (each warning is tagged with its category, e.g. [deprecation], [unchecked]); raise the javac reporting cap (-Xmaxwarns 100000) since the default 100-per-file cap silently truncated the inventory (the untruncated baseline was 1809 warnings, not 619); add scripts/collect-warnings.py, docs/warnings.md (inventory) and docs/warnings-plan.md (plan); a full fix series across every module — deprecation, unchecked, rawtypes, serial, this-escape, overrides, cast — strictly behavior-preserving (suppressions and safe cast/rawtypes widening only). The [serial] and [this-escape] categories are then disabled in the shared javac configuration (-Xlint:all,-serial,-this-escape) instead of being silenced per file: both patterns are intentional throughout the code base, and the cleanup policy keeps @SuppressWarnings("serial") without a serialVersionUID (see Policy). The cleanup passes eliminated the whole [unchecked] (125) and [rawtypes] (75) residue, the 15-warning tail ([dangling-doc-comments] 12, [lossy-conversions] 2, [static] 1), the 19 small-category warnings ([cast] 9, [overrides] 4, [try] 3, [varargs] 2, [overloads] 1), all [auxiliaryclass] (48) warnings, and finally the last remaining category, [deprecation] (110 warnings, 103 file:line sites). The residual inventory is 32 intentional [deprecation] warnings on the legacy Properties Settings overloads (kept as porting reminders while the .key/.props paths still load them), i.e. this branch introduces no warnings of any lint category beyond those 32 (generic typing where clean, wildcard widening, @SafeVarargs, Class.cast, documented suppressions at clone/visitor/reflection boundaries, Swing viewToModel2D/modelToView2D + Rectangle2D adaptations, getFileURI()→getFileUri(), new URL(String)→URI.create(...).toURL() (only at sites whose input is already a well-formed URL/URI string; the three sites that build URL strings from raw file-system paths keep the lenient new URL(...) constructor — see Policy), DefaultTermParser→KeyIO, the wholesale-deprecated Constraint API suppressed with justification since no replacement exists; orphaned doc blocks demoted to plain comments, misplaced javadoc re-attached to its declaration, and decorative //// banner comments converted to // + dashes to silence the [dangling-doc-comments] lint). Because main deprecated ImmutableArray while still referencing it at ~783 sites, enabling -Xlint:all additionally surfaces a pre-existing main baseline of 838 warnings (783 [deprecation] ImmutableArray, 46 [auxiliaryclass], 5 [try], 3 [unchecked], 1 [cast]); none of these is introduced by this branch, and the full inventory is documented as a baseline in docs/warnings.md (total 870).

Javadoc cleanup — add scripts/collect-javadoc.py (parses and groups javadoc diagnostics into build/warnings/javadoc.md; excludes javac lint noise from the javadoc-task dependencies and forces complete re-runs so the inventory is reproducible), docs/javadoc.md (inventory) and docs/javadoc-plan.md (plan with 5 disjoint workstreams). All five workstreams are complete: the key.java package overview is rewritten for the current AST model (62 dead recoder-era links); KeYJavaASTFactory links now target BinaryOperatorKind constants instead of removed operator classes; removed-type and unresolvable-member links across 8 more files are fixed; tag/HTML issues across 11 files are cleaned. Final full run: 0 errors, 0 warnings on all classic /** ... */ files; the only remaining 80 warnings are accepted residue from markdown /// doc comments, which are deliberately not rewritten (documented out of scope in the plan).

Checker-Framework build infra — the nullness builds of key.util, key.ncore, key.ncore.calculus and key.ncore.matcher previously passed -Werror, which turned every checker warning into a build failure; -Werror is removed so checker warnings no longer fail the build (the CI check ./gradlew -DENABLE_NULLNESS=true compileTestJava is green on the head). With warnings no longer fatal, two casts that javac had reported as redundant were restored because the nullness checker requires them as declarations: the (T[]) cast on the toArray result in ArrayUtil.remove and the (String[]) cast on Arrays.copyOf in Filenames.removeDotDot, both annotated @SuppressWarnings("cast") in the established checker-required-cast style.

History note

This branch originally held only the infra + inventory (8 commits) and acted as the stack base for per-category PRs. That stack was collapsed onto this branch in a strictly linear series; a follow-up history rewrite stripped all transient-modifier additions (see Policy); afterwards every commit was reformatted with Spotless (git rebase --exec 'spotlessApply; git commit --amend'). The whole range is Spotless-clean (spotlessCheck passes); scripts/format_branch_with_spotless.sh is provided to re-run the per-commit formatting via git filter-branch at any time. The javadoc fixes were developed and verified in a separate worktree, then cherry-picked onto this branch, keeping the history linear. After the checker-infra commits, a manual pass removes the javadoc reporting caps again, a leftover debug print, the //// banner comments in CheckerData, and leftover cleanup comments (Swing glue / benign notes) plus the pre-existing serialVersionUID in ReferenceSearchDialog and the then-unused @NonNull imports; a second filter-branch pass (hunk strip, backup refs/backup/cw-pre-comment-strip-20261025) removes the // Swing glue: configures the dialog during construction; benign. comment that the keyext.caching lint commit had introduced, so that comment never appears anywhere in the history. The branch was then rebased from its PR #4001 base onto main: the 24 cleanup commits replayed with conflicts resolved by keeping main's current types (e.g. ImmutableArray where main kept it, GenerationalCache where main replaced the LRU caches, KeyRangeExpression visitor overrides dropped where main removed them) while preserving each commit's warning fixes, and a final commit refreshes docs/warnings.md for the new baseline; the pre-rebase head is cbfcd2d240 (backup/pre-rebase-4004).

Policy

Per the campaign cleanup decision, every serialVersionUID / @Serial / this-escape / transient addition was stripped from the history; a @SuppressWarnings("serial") without a UID is kept (campaign policy). All added transient modifiers were stripped in the history rewrite — two commits became empty and were dropped (8f668ab39f was transient-only; the final keyext commit consisted of only the stripped TGInfoDialog reflow). Gate scans over the whole range (git diff <base>..HEAD -- '*.java' filtered for serialVersionUID|@Serial|this-escape|transient) are clean; the only remaining serialVersionUID values are pre-existing ones (the literal config string -Xlint:all,-serial,-this-escape in the root build.gradle is the deliberate exception). Javadoc ground rules: comments only, no behavior changes, and no markdown /// doc comment is rewritten; the sole exception is the dangling-doc-comments fix (c8ab774fcf), which demoted orphaned doc blocks (not attached to any declaration) to plain comments, moved misplaced javadoc onto its actual declaration, and converted decorative //// banner comments to // + dashes to silence the [dangling-doc-comments] lint, and the manual-pass banner demotions in CheckerData — no attached /// doc comment was touched. The deprecation fixes (5b505a3e84) add justified suppressions only where a real migration is unsafe or absent (e.g. the wholesale-deprecated Constraint API with no successor, the legacy Properties settings overloads the .key/.props paths still load, the workaround enableWhenProofLoaded(AbstractButton), GeneralFailureEvent whose IssueDialog successor would bypass the notification pipeline, and the three file-system-path-based new URL(String) sites whose strict URI.create(...).toURL() replacement rejected Windows backslash paths at runtime — that regression failed the first post-rebase windows-latest CI on 7 modules and was fixed by restoring the lenient constructor with this suppression); every site with a live replacement API was migrated instead.

Verification

  • testClasses builds green on the head; no behavioral changes; commits carry Co-Authored-By: OpenCode (KIT Medium) where applicable (the manual-fix commits are the author's own and carry no trailer).
  • Checker-Framework CI check (./gradlew -DENABLE_NULLNESS=true compileTestJava) green on the head — the previous failure (warnings found and -Werror specified) is resolved by the -Werror removal, and the two [return.type.incompatible] errors introduced by the cast cleanups are fixed by the restored casts above.
  • javac gate scans CLEAN over the whole range (Java sources only; infra config string excepted).
  • Final pass gate: a full --rerun-tasks testClasses build on the head reports the 870-warning baseline: the 32 intentional legacy-settings deprecation warnings plus the 838 pre-existing main warnings surfaced by -Xlint:all (783 [deprecation] ImmutableArray, 46 [auxiliaryclass], 5 [try], 3 [unchecked], 1 [cast]); 0 warnings are introduced by this branch beyond the 32 (docs/warnings.md).
  • javadoc: 0 errors, 0 warnings on all classic /** */ files in a full --rerun-tasks inventory (final: 80 residual warnings, all from intentional markdown /// comments — see docs/javadoc.md / docs/javadoc-plan.md).
  • GitHub CI on head ab816d34c9: all unit tests green on both ubuntu-latest and windows-latest (including the 7 windows modules that failed on the first post-rebase head), checkerFramework and formatting pass, and the integration suites pass. Note: that first post-rebase head (51854812c6) failed the windows-latest unit tests on 7 modules (ProblemLoaderException: Load failed, root cause the URI.create backslash strictness, see Policy); restoring the lenient new URL(...) at the three path-based sites fixed all of them.
  • History was force-pushed after the comment-hunk strip and again after the rebase onto main; the previous heads are preserved in refs/backup/cw-pre-comment-strip-20261025 and backup/pre-rebase-4004 (cbfcd2d240, the rmimarray-stacked head).

@wadoon wadoon changed the title Compiler warnings: enable -Xlint:all, baseline inventory and integration (stacked on #4001) Compiler warnings: enable -Xlint:all, baseline inventory and stack base Oct 25, 2026
@wadoon
wadoon force-pushed the weigl/cleanwarnings branch 4 times, most recently from 69d92cc to 34aee9a Compare October 25, 2026 01:04
@wadoon wadoon changed the title Compiler warnings: enable -Xlint:all, baseline inventory and stack base Fix javac lint warnings in KeY (deprecation, unchecked, rawtypes, serial, this-escape) Oct 25, 2026
@wadoon
wadoon marked this pull request as ready for review October 25, 2026 02:55
@wadoon
wadoon force-pushed the weigl/cleanwarnings branch 2 times, most recently from d8d8fa5 to c4f4125 Compare October 25, 2026 03:11
@wadoon
wadoon force-pushed the weigl/cleanwarnings branch from 18f36ad to 62de564 Compare October 25, 2026 12:18
@wadoon wadoon changed the title Fix javac lint warnings in KeY (deprecation, unchecked, rawtypes, serial, this-escape) Fix javac lint warnings in KeY (deprecation, unchecked, rawtypes) Oct 25, 2026
@wadoon
wadoon removed this pull request from stack #4014 October 26, 2026 01:21
@unp1

unp1 commented Oct 26, 2026

Copy link
Copy Markdown
Member

Thanks.

Concerning deprecation warning. I would keep them. They are real warnings and they serve as a reminder to resolve them. Using SuppressWarning in these cases hides useful reminders.

@wadoon

wadoon commented Oct 26, 2026

Copy link
Copy Markdown
Member Author

Thanks.

Concerning deprecation warning. I would keep them. They are real warnings and they serve as a reminder to resolve them. Using SuppressWarning in these cases hides useful reminders.

I see it the same way. But normally, I would distinguish: (a) deprecated outside of our scope so no action is available => suppress, or (b) deprecated in our scope: deprecation is a TODO marker for future.

I doubt, that the AI can distinguish it.

@unp1

unp1 commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

How is the plan to proceed with the PR? Should we do small commits (reverting, changing) certain fixes to lint warnings or just comments? And then a discussion about the changes and maybe reverting the reverts?

Three issues I have at the moment, just a quick random glance:

  • Undo extract auxiliary classes: at least for the Integer cost labels (we have now 5 small classes with basically just named cost, all relevant for the integer strategy but as they are not at one place, the right position or an existing will be missed as one does not know where do lool)
  • I saw at least one change where "return expr;" was rewritten into two or more statements, mainly, @SomeAnnot T tmp = expr; return expr;" because java does not allow annotations at places withing expressions. In these cases I would actually prefer the warning than the additioal lines of code.
  • Undoing some of the suprression of the deprecated warnings

@wadoon

wadoon commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

How is the plan to proceed with the PR?

A good question:

  1. Currently, it is on-top of "Remove ImmutableArray". Should we rebase it to main?
  2. I am also wondering if it would be more beneficial to just re-partition the hunks by type (criticality) into separate commits. Then we can just drop the commits and it is fine.

@wadoon
wadoon force-pushed the weigl/cleanwarnings branch from e22e452 to 11fe874 Compare October 27, 2026 20:17

@unp1 unp1 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.

From my side fine, but I assume the added docs/{javadoc-plan, javadoc, warning-plan, warnings}.md should be removed before a merge?

@wadoon
wadoon changed the base branch from weigl/rmimarray to main November 7, 2026 08:37
-Xlint: all tags every warning with its category ([deprecation], [unchecked], [rawtypes], ...) so the inventory scripts can group them.  -Xmaxwarns lifts javac's default print cap of 100 warnings per compilation unit so the inventory is complete.  The [serial] and [this-escape] categories are kept disabled deliberately: the serialization machinery and constructor-side `this` leaks are intentional throughout the code base (see scripts/collect-warnings.py).  The debug output of project descriptions in the publishing block is removed as well.
Co-Authored-By: OpenCode (KIT Medium)
collect-warnings.py and collect-javadoc.py turn the build output into the inventories in docs/; the plan files describe the ground rules and the per-category strategy.

Co-Authored-By: OpenCode (KIT Medium)
warnings.md records the baseline of the cleanup (1809 warnings across 214 files, 13 categories); javadoc.md records the baseline javadoc diagnostics.

Co-Authored-By: OpenCode (KIT Medium)
Removes a commented-out helper method, a stale TODO, stray blank lines, a redundant serialVersionUID, and unused @nonnull declarations.

Co-Authored-By: OpenCode (KIT Medium)
Package-private auxiliary classes of JavaCardDLStrategy are extracted into dedicated compilation units (DivModCost, LinearEquationCost, LinearInequationCost, NonlinearArithmeticCost, PolynomialCost; IntegerArithmeticCosts is folded into them).  LemmaFormula and LightDarkIcon leave their host files as well.  This removes the auxiliaryclass lint warnings that were reported against these classes.

Co-Authored-By: OpenCode (KIT Medium)
Widens generic signatures (Assignment<?>, the built-in rule app hierarchy, Strategy<Goal>, GoalChooser, ...), replaces raw generic array creations, applies Class.cast()/asSubclass() instead of unchecked casts, and adds type arguments to cast targets.  Includes the applyTaclet() test helper that removes the raw getExecutor() calls.

Co-Authored-By: OpenCode (KIT Medium)
@wadoon
wadoon force-pushed the weigl/cleanwarnings branch from cbfcd2d to 5185481 Compare November 7, 2026 11:53
wadoon and others added 19 commits November 7, 2026 13:16
Migrates DefaultTermParser to KeyIO, new URL()/getFileURI() to URI.create()/getFileUri(), and java.awt Rectangle viewToModel/modelToView to the viewToModel2D variants; removes @Deprecated/(@deprecated) markers that are no longer needed and re-routes settings through Configuration.

Co-Authored-By: OpenCode (KIT Medium)
Drops casts that the compiler no longer needs (now-typed find()/clone()/verdict() results and similar); the -Xlint:cast warning is resolved by deleting the cast.

Co-Authored-By: OpenCode (KIT Medium)
KeYEnvironment, ZipFileCollection and DataRecordingTable close() no longer declare the unnecessarily broad Exception/IOException contract.

Co-Authored-By: OpenCode (KIT Medium)
ProgramMethod, SMTSolverResult, Heap, Metavariable, SequentView's view-state record and WeakValueLinkedHashMap's entry now honour equals()/hashCode().

Co-Authored-By: OpenCode (KIT Medium)
Static accesses are made explicit, @SafeVarargs markers that are no longer needed are removed, one cast loses its redundant parentheses, a text block's indentation is fixed, and the serialization helpers readObject/writeObject are renamed to *SerializedObject so they no longer collide with the serialization machinery's special methods.

Co-Authored-By: OpenCode (KIT Medium)
The last raw-type usages cannot be resolved by widening alone; they are documented with an @SuppressWarnings annotation and a comment explaining why the warning is accepted.

Co-Authored-By: OpenCode (KIT Medium)
Some callers intentionally use the deprecated members (legacy AST diagnostics, debug output).  Each site is annotated with @SuppressWarnings("deprecation") and a brief comment.

Co-Authored-By: OpenCode (KIT Medium)
Resource closers that cannot afford to declare the exceptions of their close() call are annotated with @SuppressWarnings("try").

Co-Authored-By: OpenCode (KIT Medium)
Serializable classes that intentionally skip serialVersionUID are annotated with @SuppressWarnings("serial").

Co-Authored-By: OpenCode (KIT Medium)
The SMT translators, JavaCardDLStrategy and the keyboard taclet test tolerate the remaining auxiliary classes; the usages are adjusted and annotated.

Co-Authored-By: OpenCode (KIT Medium)
The few remaining redundant casts and the varargs heap-pollution warnings are documented with @SuppressWarnings.

Co-Authored-By: OpenCode (KIT Medium)
Javadoc blocks that javadoc treats as dangling (not attached to a declaration) are turned into plain comments or moved to the declaration they describe; ///-style markdown doc comments are converted to regular comments.

Co-Authored-By: OpenCode (KIT Medium)
Corrects malformed javadoc: broken {\@link}/{@code} markup, wrong tag casing, and missing documentation on public API surfaces.

Co-Authored-By: OpenCode (KIT Medium)
…scape residue

The NullnessChecker previously ran with -Werror in key.util and the key.ncore modules; the flag is dropped so the nullness analysis no longer hard-fails.  The intentional constructor side-effects in keyext.caching are documented on the affected members.

Co-Authored-By: OpenCode (KIT Medium)
The cleanup is finished: warnings.md and javadoc.md now reflect the final warning and javadoc state of the repository.

Co-Authored-By: OpenCode (KIT Medium)
- Cost labels for the integer strategy should be grouped in one location so taht they can be easily found
- The global comment was moved to a more or less randomly chosen sub category and was not of much help there
Per review comment on ProofDependentSMTSettings ("All these legacy
properties-based warnings are valid warnings and should not be suppressed,
we should keep them as a reminder to port to the new framework"), the
@SuppressWarnings("deprecation") markers are removed from every legacy
Properties-based settings path:

- all readSettings(Properties)/writeSettings(Properties) overrides of the
  deprecated Settings API (11 settings classes in key.core plus
  TestGenerationSettings and IsabelleTranslationSettings)
- the Properties-based loader/snapshot paths in ProofIndependentSettings
  (load/saveSettings/addSettings) and ProofSettings (update/addSettings)
- the AbstractOperationPO symbolic-execution term-label counter site, which
  should remain a reminder until the symbolic_execution residue is removed

The [deprecation] warnings (32) now surface again in the build and are
recorded as intentional residue in docs/warnings.md.

Co-Authored-By: OpenCode (KIT Medium)
Per unp1's review, temp variables introduced solely to carry an
@SuppressWarnings (or a single-use value) are not worth the extra lines:

- Modality.kind(): @SuppressWarnings("unchecked") moved to the method
  declaration, `return (K) kind;` restored (no temp local)
- SingleRuleApplicationInfo.getGoal(): same treatment
- IssueDialog.getHyperlinkElement(): inline the single-use Point2D local;
  the now-unused java.awt.geom.Point2D import is dropped
- IntermediateProofReplayer.parseTerm(): the repeated
  proof.getNamespaces() calls behind one local (the fresh NamespaceSet is
  kept to avoid mutating the proof's live namespaces)

Co-Authored-By: OpenCode (KIT Medium)
The branch now sits on origin/main, where ImmutableArray is deprecated
while still referenced ~783 times. With the PR's -Xlint:all flag those
pre-existing sites (plus 46 auxiliaryclass, 5 try, 3 unchecked and 1
cast warning) are surfaced and documented here as a baseline: the PR
itself introduces no new warnings beyond the 32 intentional
deprecation warnings of the legacy Properties settings paths.
@wadoon
wadoon force-pushed the weigl/cleanwarnings branch from 5185481 to ab816d3 Compare November 7, 2026 12:17
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.

2 participants