]> source.dussan.org Git - aspectj.git/commitdiff
Revert WeavingAdaptor generated class map optimisation
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 8 Apr 2024 11:40:01 +0000 (13:40 +0200)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 8 Apr 2024 12:51:59 +0000 (14:51 +0200)
This was introduced in commit 8a4aa03845 of PR #278 contribution as part
of the #279 fix. The contributor thought that the generated closure
class entries were never used, but in fact AJDT class OSGiWeavingAdaptor
relies on the presence of those entries.

To the best of my present knowledge, it looks as if this change was the
root cause of https://github.com/eclipse-aspectj/ajdt/issues/57.
Therefore, I reverted it, simultaneously refactoring Iterator::remove
usage to delete entries from the map to Collection::removeIf.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
loadtime/src/main/java/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
weaver/src/main/java/org/aspectj/weaver/tools/WeavingAdaptor.java

index a18400e9026d5bb29a159683a4a63ae57d04cf94..223008f8f8ba760c55358fc2e0124269fb4b957d 100644 (file)
@@ -1008,8 +1008,16 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
         * @param className a slashed classname (e.g. com/foo/Bar)
         */
        public void flushGeneratedClassesFor(String className) {
-               String dottedClassName = className.replace('/', '.');
-               generatedClasses.remove(dottedClassName);
+               try {
+                       String dottedClassName = className.replace('/', '.');
+                       String dottedClassNameDollar = dottedClassName + "$"; // to pick up inner classes
+                       generatedClasses.entrySet().removeIf(entry -> {
+                               String generatedClassName = entry.getKey();
+                               return generatedClassName.equals(dottedClassName) || generatedClassName.startsWith(dottedClassNameDollar);
+                       });
+               } catch (Throwable t) {
+                       new RuntimeException("Unexpected problem tidying up generated classes for " + className, t).printStackTrace();
+               }
        }
 
        private static final Object lock = new Object();
index 9ee4c0962776ba5eec1b349fa884ff85dc7202b8..42a4e37eedad21bcc77dc87ceadeec591f540f6b 100644 (file)
@@ -939,6 +939,7 @@ public class WeavingAdaptor implements IMessageContext {
                                                lacache.addGeneratedClassesNames(wovenClass.getClassName(), wovenClass.getBytes(), result.getClassName());
                                        }
 
+                                       generatedClasses.put(className, result);
                                        generatedClasses.put(wovenClass.getClassName(), wovenClass);
                                        generatedClassHandler.acceptClass(className, null, resultBytes);
                                }