From 292e95de4c341c1c46bbdef3577e3478fc843060 Mon Sep 17 00:00:00 2001 From: liuzhengyang Date: Sun, 9 Oct 2022 18:59:44 +0800 Subject: [PATCH 1/2] Fix enum field update, change ENUM to --- .../java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java b/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java index 06043ef85..8ba1f9029 100644 --- a/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java +++ b/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java @@ -94,8 +94,8 @@ public void edit(FieldAccess f) throws CannotCompileException { reinitializeStatics[0] = true; } if (originalField != null) { - // ENUM$VALUES is last in enumeration - if (originalClass.isEnum() && "ENUM$VALUES".equals(f.getFieldName())) { + // $VALUES is last in enumeration + if (originalClass.isEnum() && "$VALUES".equals(f.getFieldName())) { if (reinitializeStatics[0]) { LOGGER.debug("New field will be initialized {}", f.getFieldName()); } else { @@ -149,7 +149,7 @@ private static boolean checkOldEnumValues(CtClass ctClass, Class originalClas try { CtField existing = ctClass.getDeclaredField(en.toString()); } catch (NotFoundException e) { - LOGGER.debug("Enum field deleted. ENUM$VALUES will be reinitialized {}", en.toString()); + LOGGER.debug("Enum field deleted. $VALUES will be reinitialized {}", en.toString()); return true; } } From f4d0660dab4f22dcc6b21abc1af2e92ea74fb6ea Mon Sep 17 00:00:00 2001 From: liuzhengyang Date: Tue, 11 Oct 2022 14:43:19 +0800 Subject: [PATCH 2/2] javac generate , eclipse compiler generate ENUM --- .../java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java b/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java index 8ba1f9029..bb706d1ed 100644 --- a/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java +++ b/hotswap-agent-core/src/main/java/org/hotswap/agent/plugin/jvm/ClassInitPlugin.java @@ -94,8 +94,11 @@ public void edit(FieldAccess f) throws CannotCompileException { reinitializeStatics[0] = true; } if (originalField != null) { - // $VALUES is last in enumeration - if (originalClass.isEnum() && "$VALUES".equals(f.getFieldName())) { + // Enum class contains an array field, in javac it's name starts with $VALUES, + // in eclipse compiler starts with ENUM$VALUES + if (originalClass.isEnum() && f.getSignature().startsWith("[L") + && (f.getFieldName().startsWith("$VALUES") + || f.getFieldName().startsWith("ENUM$VALUES"))) { if (reinitializeStatics[0]) { LOGGER.debug("New field will be initialized {}", f.getFieldName()); } else {