From 62da8c362160ab02cd80b5b6d19d7d6f5c0b2901 Mon Sep 17 00:00:00 2001 From: Col-E Date: Fri, 18 Feb 2022 18:58:19 -0500 Subject: [PATCH] fix: Re-introduce limited case CP pruning due to incomplete class spec insights --- .../transform/IllegalStrippingTransformer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java b/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java index 7b6da8b..4c4ec85 100644 --- a/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java +++ b/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java @@ -104,8 +104,18 @@ public void transform() { if (index == 0 || index >= max - 1) continue; ConstPoolEntry cpe = pool.get(index); - logger.info("Removing now unused CP entry: {}={}", index, cpe.getClass().getSimpleName()); - pool.set(index, new CpInt(0)); + switch (cpe.getTag()) { + case ConstantPool.DYNAMIC: + case ConstantPool.INVOKE_DYNAMIC: + logger.debug("Removing now unused CP entry: {}={}", index, cpe.getClass().getSimpleName()); + pool.set(index, new CpInt(0)); + break; + default: + // TODO: When the full class file specification is complete we can aggressively prune other types. + // - for now we only remove specific X_DYNAMIC types since we can be sure removing them is safe + // in the context of references to it being removed due to an invalid BootstrapMethodsAttribute + break; + } } }