Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

codecholeric
Copy link
Collaborator

@codecholeric codecholeric commented Nov 26, 2023

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

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 may generate bytecode instantiating and using a `StringBuilder` (depending on the JDK version).
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.

Signed-off-by: Peter Gafert <peter.gafert@archunit.org>
@codecholeric codecholeric force-pushed the fix-problem-with-synthetic-access-on-string-concat branch from a6fdc9d to cabbe13 Compare December 3, 2023 10:10
@codecholeric codecholeric merged commit 4b0a225 into main Dec 3, 2023
21 checks passed
@codecholeric codecholeric deleted the fix-problem-with-synthetic-access-on-string-concat branch December 3, 2023 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants