| name | java-patch-workflow |
| description | Workflow for creating and applying patches to Java projects - diff format, patch application, and Maven rebuilds for security fixes. |
Java Patch Workflow
Creating Unified Diff Patches
diff -u original_file.java modified_file.java > my_fix.patch
diff -u -p original.java modified.java > fix.patch
patch -p1 < fix.patch
patch -p0 < fix.patch
patch --dry-run -p1 < fix.patch
Git-Based Patching
git diff HEAD > my_fix.patch
git format-patch HEAD~1
git am patch_file.patch
git apply patch_file.patch
git apply --check patch_file.patch
Apache Druid Build
Full Build (skip web-console for OOM prevention)
cd /root/druid
mvn clean package -DskipTests \
-Dcheckstyle.skip=true -Dpmd.skip=true \
-Dforbiddenapis.skip=true -Dspotbugs.skip=true \
-Danimal.sniffer.skip=true -Denforcer.skip=true \
-Djacoco.skip=true -Ddependency-check.skip=true \
-pl '!web-console' -pl indexing-service -am
Module-Specific Build
mvn package -DskipTests -pl indexing-service -am
mvn package -DskipTests -Dcheckstyle.skip=true -pl processing
Patch File Organization
/root/patches/
├── 01-fix-javascript-injection.patch # Primary root cause fix
├── 02-fix-sampler-validation.patch # Defense in depth
└── README.md # Fix description
Common Issues
Patch Offset Errors
If patch reports "offset" or "fuzz", the patch may be for a different file version.
Use patch --fuzz=3 to allow more context flexibility.
Build Failures After Patch
- Check for compilation errors:
mvn compile first
- Verify imports are added for new classes used
- Check Guice injection: ensure
@Inject annotation is present for DI
Finding the Right JAR After Build
find /root/druid -name "druid-indexing-service-*.jar" -not -path "*/test*"