This repository packages Eclipse's Java Development Tools (JDT) for SonarJava, including patches needed by the Java analyzer. The maintenance instructions below explain how to update JDT and test the resulting package with SonarJava.
To learn more about Sonar’s Java analysis, visit the Sonar website.
This repository exists because we need to patch some files from Eclipse JDT to fix some issues, but we can only do this in a repository with the same license as Eclipse.
When a new version of JDT is released, we update the dependency and reapply the complete ordered patch series in patches/series.
Eclipse Public License - v 2.0 see LICENSE.
scripts/patchJDT.py is the command-line tool for maintaining SonarJava's changes to Eclipse JDT. It keeps the upstream dependency, the patches, and the patched Java sources consistent when upgrading JDT or changing a fix.
Most of JDT is packaged directly from Maven dependencies. This repository also contains complete copies of a few upstream classes:
ASTParser, ClasspathJar, ClasspathJmod, ClasspathMultiReleaseJar, ProblemHandler, and ProblemReporter. Maven compiles these local copies and includes them as
replacements for the original classes in jdt-package. Each copy contains the upstream implementation plus small changes needed by SonarJava.
Updating only the dependency version would leave these replacements based on an older implementation; replacing them with pristine
upstream sources would discard the SonarJava fixes. The tool updates both parts together by applying the complete patch series to
the new upstream sources.
The files involved have distinct roles:
| File or directory | Role |
|---|---|
| pom.xml | Selects the JDT Core dependency that Maven packages. |
| patches/upstream.json | Records the upstream baseline: JDT Core and ECJ versions, SHA-256 checksums of their POMs and source JARs, and the source files to replace. |
| patches/series | Lists every active patch in application order, including patches that depend on earlier ones. |
patches/*.patch |
Describe the individual SonarJava changes to upstream code, grouped by purpose and independent of Git commit history. |
| src/main/java/org/eclipse/jdt/ | Contains the patched replacement classes that Maven compiles, together with separately maintained local helpers. |
For the replacement classes listed in the manifest, the tool enforces this relationship:
Published upstream sources + patches applied in series order = checked-in replacement sources
The checked-in replacement sources make ordinary Maven builds and IDE use straightforward. The patches record how to recreate those
sources and carry the fixes forward to another release. A reconstruction check compares the recreated files byte for byte with the
checked-in copies, catching changes that were made on only one side. Local helpers such as SystemReleaseClasspath.java are maintained
as ordinary project source; they are preserved during upgrades and are not reconstructed from upstream.
The baseline comes from published Maven source JARs, so it corresponds to the binaries being packaged. The tool reads the ECJ
version from JDT Core's published POM; the two versions can differ (for example, JDT Core 3.47.0 uses ECJ 3.46.100).
Run the tool with Python 3.9+ and Git installed. The examples below assume the repository root as the working directory:
Command after python3 scripts/patchJDT.py |
What it does |
|---|---|
check |
Verifies the current dependency version, pinned artifact checksums, patch list, and exact reconstruction of the replacement sources. Leaves project files untouched. |
update VERSION |
Prepares the given JDT Core release, reapplies and refreshes all patches, then writes the verified sources, patches, baseline metadata, and dependency version back to the project. |
edit PATCH.patch |
Opens a temporary workspace for changing an existing patch, or appending a new patch. Prints where to edit the Java sources and how to continue. Project files are updated only after continuation succeeds. |
continue WORKSPACE |
Regenerates the pending patch from the edited workspace sources, applies the remaining patches, and writes the complete result back after verification. |
continue --drop WORKSPACE |
Explicitly removes an empty pending patch, for example when upstream has incorporated the fix, and resumes the remaining patches. |
Run python3 scripts/patchJDT.py --help for the command list, or add --help after a command for its options.
The tool changes working-tree files; Git staging, commits, and pushes remain manual. Building the package and validating it in
SonarJava are separate steps described below. Ordinary Maven builds do not run the maintenance tool; CI runs its reconstruction
check before building.
The Eclipse IDE follows a quarterly release schedule (typically March, June, September, December). You can find the release history on wikipedia.
Compare the org.eclipse.jdt:org.eclipse.jdt.core version in pom.xml with the published releases at:
- https://central.sonatype.com/artifact/org.eclipse.jdt/org.eclipse.jdt.core
- https://mvnrepository.com/artifact/org.eclipse.jdt/org.eclipse.jdt.core
# Verify the existing dependency, baseline checksums, complete patch series, and generated sources.
python3 scripts/patchJDT.py check
# Replace 3.47.0 with the target published JDT Core release.
python3 scripts/patchJDT.py update 3.47.0Both commands first read artifacts from ~/.m2/repository, and download missing ones into a temporary workspace, retrying transient
failures (network errors, HTTP 429 and 5xx) up to three times. Downloads come from Maven Central by default. When
SONARSOURCE_REPOSITORY_URL is set, as the build-maven action does in CI, they come from that repox repository instead, authenticated
with ARTIFACTORY_ACCESS_TOKEN (and ARTIFACTORY_USERNAME) over HTTPS only; use --repository-url URL to select another repository
(credentials are never sent to it). The tool never writes to the local Maven repository. Use --offline to require cached artifacts, or
--maven-repo PATH to select a different local repository. These options follow the command, for example
python3 scripts/patchJDT.py check --offline.
update also compares every artifact it is about to pin (including cached ones) with the .sha1 files published next to it in the
repository, so a corrupted or tampered local copy cannot become the new baseline. With --offline this verification is impossible and
the tool prints a warning. check additionally verifies that the maven-shade-plugin filter for org.eclipse.jdt:* in pom.xml
excludes the .class and .java files of every replacement source, so the shaded jar cannot contain the unpatched upstream classes.
An update proceeds in a temporary workspace:
- Reconstruct and verify the current replacement sources before attempting to upgrade them.
- Resolve the target JDT Core and ECJ versions and obtain the pristine replacement sources from their published artifacts.
- Apply every patch in
patches/seriesin order. Regenerate each successful patch against the target sources while preserving its description and its place in the series. If a patch conflicts, pause for the manual resolution described below. - Verify that the refreshed series recreates the staged result, then write the replacement sources,
pom.xml, patches, andpatches/upstream.jsonback to the project together.
Refreshing a patch updates its diff to match the new upstream implementation; it preserves the edits introduced by that patch. Successful textual application still needs behavioral validation through the tests and downstream checks described below.
If a patch cannot be applied, the command exits unsuccessfully and prints the retained workspace path. Project files have not been
changed. work/ contains the target upstream sources with all earlier patches applied; before/ is the state immediately before
the pending patch. Application uses git apply --check before git apply, without partial .rej application.
- Inspect the named patch under the workspace's
patches/directory and the upstream changes. - Edit the managed Java files in
WORKSPACE/work/to implement that patch's intended behavior. Preserve the earlier patches. - Update its description in
WORKSPACE/patches/PATCH.patchif needed; the diff is regenerated from the edited Java files. - Resume with:
python3 scripts/patchJDT.py continue WORKSPACEPrinted continuation commands use the current Python interpreter and absolute paths, so they can be run from any directory.
The tool refreshes only the pending patch and then applies the remaining patches in order. A later conflict pauses in the same way.
If upstream has incorporated a patch completely, leave work/ identical to before/ for that step and explicitly remove it with:
python3 scripts/patchJDT.py continue --drop WORKSPACEAn empty pending patch is otherwise an error, so accidentally continuing an unresolved conflict cannot silently discard a fix. To abandon a staged update, discard its temporary workspace; project files are updated only after all patches have been resolved and verified.
A second tool, scripts/localJDT.py, supports developing and testing upstream JDT locally.
The two tools in scripts/ have separate responsibilities:
| Tool | Responsibility |
|---|---|
scripts/localJDT.py |
Clone JDT, select a branch, build its working tree, and run tests. |
scripts/patchJDT.py |
Obtain released or locally built artifacts, maintain/apply our patches, and build and test the shaded package. |
Install Python 3.9+, Git, and Maven. The current BETA_JAVA28 branch requires Java 25
or newer; set JAVA_HOME accordingly. Packaging published releases normally needs
Java 21 or newer. The commands below run from this repository root, but script paths
and workspaces are resolved relative to the scripts, independently of your current directory.
# Clone and create a local tracking branch, without building:
python3 scripts/localJDT.py checkout BETA_JAVA28
# Build the branch, including local commits and uncommitted changes:
python3 scripts/localJDT.py build BETA_JAVA28 --java-home "$JAVA_HOME"
# After editing the checkout, rebuild its current branch or detached revision:
python3 scripts/localJDT.py build --java-home "$JAVA_HOME"The checkout is in workdir/local-jdt/eclipse.jdt.core. Existing local branches and edits
are preserved. Normal Git checkout rules protect changes when switching branches;
the tool never resets, rebases, cleans, stashes, or automatically detaches the checkout.
An existing local branch is not automatically fetched or updated. checkout --fetch
fetches remote references without merging or moving local branches. Choose how to
incorporate upstream changes using Git inside the checkout.
Edit sources and add regression tests directly in that checkout. To run a targeted upstream compiler regression suite:
python3 scripts/localJDT.py test \
--test org.eclipse.jdt.core.tests.compiler.regression.ConditionalExpressionTest \
--compliance 25 --java-home "$JAVA_HOME"--test also accepts Class#method where supported by the upstream runner. Use
--module to select another test module inside the checkout. The build skips upstream
tests; the test command runs them explicitly. It uses the same private Maven repository
as the build, so build first to install the needed local artifacts.
Both tools accept --java-home /absolute/path/to/jdk on build/test/package commands.
This is useful when Python version-manager shims overwrite JAVA_HOME. For ordinary
release-maintenance commands (check, edit, update, continue), no Java invocation is needed.
JDT builds use scripts/jdt-settings.xml and workdir/local-jdt/m2, preserving artifacts
in ~/.m2/repository. The first build may download dependencies again. Each run retains
a workdir/local-jdt/build-*/ directory with build.log, build.json, and immutable
copies of the Core/compiler-batch binaries, matching source JARs, and POMs. The build
record captures the revision, working-tree status, input hashes, artifact coordinates,
and checksums. It is the interface between the two scripts; packaging never invokes
localJDT.py or accesses the live checkout. Upstream test logs are retained under
workdir/local-jdt/test-*/tests.log.
Use the build directory printed by localJDT.py:
python3 scripts/patchJDT.py package \
--local-build workdir/local-jdt/build-EXAMPLE \
--java-home "$JAVA_HOME"A path to its build.json is also accepted. This reuses the captured artifacts without
rebuilding or changing JDT, even if the checkout or its Maven cache has since changed.
Missing artifacts, altered checksums, or source JARs that disagree with recorded build
inputs are rejected. Further upstream edits require a new local build record.
To test packaging directly against a published Core version instead:
python3 scripts/patchJDT.py package --version 3.47.0 --java-home "$JAVA_HOME"The release path obtains matching Core and ECJ binaries, source JARs, and POMs, resolving
the ECJ version from Core's POM. --repository-url, --maven-repo, and --offline are
available. Online downloads verify published checksums; offline mode requires cached
artifacts and Maven plugins/dependencies and cannot verify newly selected bytes remotely.
The pinned release's source/POM checksums are checked even offline.
Packaging runs in workdir/patched-jdt/package-*/, with its own Maven repository at
workdir/patched-jdt/m2 by default. The captured artifacts are installed there, rather
than into your normal Maven repository. An explicit --maven-repo overrides that cache.
The command copies the packaging project, including local helpers in src/main and
repository tests. It regenerates the managed replacement classes from the selected
upstream source JARs plus patches/series, then configures a temporary dependency POM
while preserving tests and shading exclusions. Maven compiles and shades the package
and runs its unit and integration tests against the resulting JAR. This detects both
patch-application conflicts and behavior or compilation incompatibilities.
The source repository's POM, checked-in replacement sources, tests, patch series, and release baseline remain unchanged. The resulting package is not installed or deployed. The release-maintenance commands above still explicitly update working-tree sources and patches when requested.
Each packaging workspace retains:
input.jsonandartifacts/: the selected baseline, checksums, and frozen inputs;pristine/andbefore/: managed sources before patching and before the pending patch;packaging/: the isolated project, shaded JAR, and test reports undertarget/;packaging.json: patch progress, conflict resolutions, dependencies, and final status;install.log,dependencies.log, andpackaging.log: Maven output.
The local baseline is recorded separately from the tracked release-only
patches/upstream.json. Do not run release check against the experimental overlay or
copy its POM back into this repository.
Inspect the named patch in WORKSPACE/packaging/patches/ and edit the affected Java
files under WORKSPACE/packaging/src/. Then continue:
python3 scripts/patchJDT.py continue-package WORKSPACE --java-home "$JAVA_HOME"Only the pending patch in that workspace is refreshed, then later patches are applied
and the shaded package is rebuilt and tested. If upstream already contains the fix,
leave that step's sources identical to before/ and explicitly drop it from the
experimental series with continue-package WORKSPACE --drop.
The same continuation command retries a failed packaging build after fixing staged
helpers or configuration. If an offline run lacks dependencies, add --online to the
continuation command to allow Maven downloads; --offline forces cached resolution. Frozen artifacts and pristine sources are verified before
reuse. Repository patches are never published by these experimental commands. Keep
permanent packaging fixes through the normal edit / continue maintenance workflow.
patches/series is the authoritative application order. Every *.patch in patches/ must appear exactly once. Patches are grouped
by behavior, can affect multiple replacement classes, and may depend on earlier patches. Their headers document the purpose,
upstream context, and relevant tests. patches/upstream.json pins the JDT Core and ECJ versions, SHA-256 checksums of their
POMs and source JARs, and the mapping from upstream sources to local replacement files.
Maintain existing patches through a temporary edit session:
python3 scripts/patchJDT.py edit 0004-select-system-release-api.patch
# Edit the files under the printed WORKSPACE/work/ and, if needed, the patch description.
python3 scripts/patchJDT.py continue WORKSPACEFor a new behavior, pass a new patch filename to edit; it is appended after all existing patches. Supply a meaningful patch header
in the printed workspace before continuing. To remove an existing patch, start an edit session for it, restore the managed files in
work/ to their before/ contents, and use continue --drop. Later patches may need adaptation if they depended on the removed fix.
Edit the staged copies of upstream classes, rather than editing the committed replacement sources directly. Local helpers, tests,
and Maven configuration remain ordinary project files and do not belong in upstream patches. To override another upstream class,
add its source/destination mapping to the manifest, initially copy its pristine source into src/main/java, and update the Shade
exclusions before starting a patch edit session. This makes the new file part of reconstruction and preserves the existing fixes.
Before submitting a change, run:
python3 scripts/patchJDT.py check
mvn verifyCI runs the reconstruction check before the Maven build. Reconstruction detects missing patches, dependency
or baseline drift, and source changes that were not recorded in a patch. It does not replace behavioral tests or downstream validation.
The Maven integration tests run after packaging and verify that the compiler and replacement classes are loaded from the
shaded JAR with assertions enabled. They compile and execute valid Java code, reject invalid code with expected diagnostics,
exercise the problem-context and missing-type fixes, and check that batch parsing delivers every AST while preserving known
type bindings despite unresolved types. Release API and projectless classpath behavior are also covered. These checks run
with mvn verify; mvn package alone does not execute them. Release API verification requires a full JDK with lib/ct.sym
and a Java compiler, and fails if these prerequisites are missing. Test reports are written to target/failsafe-reports.
Every file in src/main/java must carry the Eclipse Public License 2.0 notice (including SPDX-License-Identifier: EPL-2.0).
Files that override an ECJ class keep their original Eclipse (IBM) copyright header, and files that we wrote ourselves
carry the Copyright (C) SonarSource copyright. Both rules are enforced at build time by EclipseLicenseHeaderTest:
a class is considered overridden when it also exists in the org.eclipse.jdt.core or ecj jar.
Once we have a branch of sonar-java-jdt with the new version, we can test that version on sonar-java, either using a
SNAPSHOT version when installed locally, or a build version when there is a PR on sonar-java-jdt.
The dependency on sonar-java-jdt is in the sonar-java-frontend module, artifact jdt-package.
When the sonar-java-jdt version is updated there may be compilation errors caused by changes in the API that need to be fixed on
the sonar-java side.
We need to check the new version does not cause issue on sonar-java, in particular checking peach results are not badly impacted.
As an optional step, it is a good idea to look at the diff for the parts of the eclipse-jdt-core library that are used in sonar-java.
If possible, we should also look for example repositories that use features of the new Java versions, and add them on peach.
Once we validated that the new version of sonar-java-jdt works with sonar-java (using peach results and possibly new projects), we need to release
sonar-java-jdt so that sonar-java does not depend on an unreleased version.
The current modifications are maintained as five patches:
| Patch | Purpose |
|---|---|
0001-preserve-problem-context.patch |
Avoid aborting analysis on unreportable semantic problems and preserve the problem context. |
0002-tolerate-missing-type-assertion.patch |
Tolerate methods incorrectly tagged as containing missing types. |
0003-allow-projectless-system-library.patch |
Support projectless environments with custom platform classpaths, including Android. |
0004-select-system-release-api.patch |
Delegate platform API selection to the separately maintained SystemReleaseClasspath helper. |
0005-cache-jar-compilation-unit-lookups.patch |
Backport upstream f55dfc33757c: index compilation unit packages once per archive, including JMODs and multi-release JARs (JAVA-7277). |
The following notes describe historical baseline imports. The current updater uses Maven sources and the checked-in series instead of these manual downloads or historical override commits.
In order to update org.eclipse.jdt.core to 3.46.0, the following files have been downloaded and patched to fix the (...) is wrongly tagged as containing missing types in sanity tests and the Missing system library problem in ASTParser.getClasspath(...).
ProblemHandler.java was unchanged upstream between R4_38 and R4_40, so it did not need to be re-fetched.
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_40/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_40/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java > src/main/java/org/eclipse/jdt/core/dom/ASTParser.javaIn order to update org.eclipse.jdt.core to 3.41.0, the following files have been downloaded and patched to fix the referenceContext == null problem
, the Missing system library problem in ASTParser.getClasspath(...) and the (...) is wrongly tagged as containing missing types in sanity tests.
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_35/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_35/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_35/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java > src/main/java/org/eclipse/jdt/core/dom/ASTParser.javaIn order to update org.eclipse.jdt.core to 3.39.0, the following files have been downloaded and patched to fix the referenceContext == null problem:
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_33/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_33/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
In order to update org.eclipse.jdt.core to 3.38.0, the following files have been downloaded and patched to fix the referenceContext == null problem:
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_32/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
curl -sSLf -o - https://raw.githubusercontent.com/eclipse-jdt/eclipse.jdt.core/R4_32/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java > src/main/java/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
JDT core 3.36.0 and 3.37.0 introduce a bug which prevent analysis of files when there are semantic problems.
The ProblemReporter could have a null referenceContext during the resolution of unknown types which produces
AbortCompilation exception, instead of adding the semantic problems to the compilation result.
The logic in ProblemReporter is sometimes wrong, and it wrongly set referenceContext to null.
For the Java analyzer, it's an important problem because even when the semantic is not 100% resolved, we still want
to analyze the source code. And this bug also silently prevent the following files in the same compilation batch to be analyzed.
Modified source code in the SONARJAVA-4 Fix the referenceContext == null problem commit:
- https://github.com/eclipse-jdt/eclipse.jdt.core/blob/R4_31/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
- https://github.com/eclipse-jdt/eclipse.jdt.core/blob/R4_31/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java