Skip to content

Commit 999092f

Browse files
alvdavicliveverghese
authored andcommitted
Remove filtering from PatchSetPatcher
1 parent 8eb75eb commit 999092f

File tree

1 file changed

+3
-28
lines changed

1 file changed

+3
-28
lines changed

src/main/java/com/amazon/corretto/hotpatch/patch/impl/set/PatchSetPatcher.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public abstract class PatchSetPatcher implements Patcher {
3434
private Instrumentation instrumentation;
3535
private Logger logger;
3636
private ClassFileTransformer transformer;
37-
private List<ClassTransformerHotPatch> enabledPatches;
3837

3938
protected abstract List<ClassTransformerHotPatch> getPatches();
4039

@@ -44,8 +43,7 @@ public int install(final Map<String, String> args, final int asmApiVersion, fina
4443
this.instrumentation = instrumentation;
4544
this.logger = logger;
4645

47-
this.enabledPatches = getEnabledPatches(args);
48-
this.transformer = new PatchSetTransformer(enabledPatches, asmApiVersion, logger);
46+
this.transformer = new PatchSetTransformer(getPatches(), asmApiVersion, logger);
4947

5048
if (staticAgent) {
5149
// As we are being installed during startup, we don't care about retransforming. The transformer will
@@ -59,7 +57,7 @@ public int install(final Map<String, String> args, final int asmApiVersion, fina
5957
boolean patchesApplied = false;
6058
for (Class<?> c : instrumentation.getAllLoadedClasses()) {
6159
String className = c.getName();
62-
for (ClassTransformerHotPatch patch : enabledPatches) {
60+
for (ClassTransformerHotPatch patch : getPatches()) {
6361
if (patch.isTargetClass(className)) {
6462
logger.log("Patching + " + className + " (" + c.getClassLoader() + ") with patch "
6563
+ patch.getName());
@@ -90,7 +88,7 @@ public int uninstall() {
9088
// Retransform after we've removed the transformer to restore the initial class versions.
9189
for (Class<?> c : instrumentation.getAllLoadedClasses()) {
9290
String className = c.getName();
93-
for (ClassTransformerHotPatch patch : enabledPatches) {
91+
for (ClassTransformerHotPatch patch : getPatches()) {
9492
if (patch.isTargetClass(className)) {
9593
logger.log("Un-Patching " + c + " (" + c.getClassLoader() + ") of " + patch.getName());
9694
try {
@@ -124,29 +122,6 @@ public String getFullDescription() {
124122
return sb.toString();
125123
}
126124

127-
/**
128-
* Filters the result of getPatches based on the agent arguments. This is because besides what patches are defined
129-
* in a patch set, some of them can be disabled via command line arguments ,
130-
* @param args String with the arguments that was received by the agent,
131-
* @return A list with all the patches that are enabled,
132-
*/
133-
private List<ClassTransformerHotPatch> getEnabledPatches(final Map<String, String> args) {
134-
if (args == null) {
135-
return getPatches();
136-
}
137-
List<ClassTransformerHotPatch> enabledPatches = new ArrayList<>();
138-
outer: for (ClassTransformerHotPatch patch : getPatches()) {
139-
for (String key : args.keySet()) {
140-
if (key.equals("disable-" + patch.getName())) {
141-
// Do not add the current patch to the list of patches to apply
142-
continue outer;
143-
}
144-
}
145-
enabledPatches.add(patch);
146-
}
147-
return enabledPatches;
148-
}
149-
150125
private static class PatchSetTransformer implements ClassFileTransformer {
151126
private final Logger logger;
152127
private final int asmApiVersion;

0 commit comments

Comments
 (0)