TNG / ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
http://archunit.org
Apache License 2.0
3.18k stars 288 forks source link

fix importing inner class using string concat of outer field #1203

Closed codecholeric closed 9 months ago

codecholeric commented 9 months ago

We weren't aware that the compiler occasionally generates synthetic access$123 methods that call constructors. More precisely for the following constellation

class Outer {
  String field = "";
  class Inner {
    void concat() {
      field += "any";
    }
  }
}

the compiler generates bytecode instantiating and using a StringBuilder. But for constructor calls the synthetic access resolution was not hooked in, because we assumed that those methods would never call a constructor. This in turn lead to the bug

java.lang.IllegalStateException: Never found a JavaCodeUnit that matches supposed origin CodeUnit{name='access$123'...

I.e. the method access$123 was filtered out as synthetic, but the origin of the constructor call had not been resolved to the actual Inner.concat method.

Resolves: #1146 Resolves: #1194