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

[BUG] Calling getEnclosingClass() on a nested class does provide a JavaClass with no members #1216

Open
erikmaas-malmberg opened this issue Dec 14, 2023 · 3 comments

Comments

@erikmaas-malmberg
Copy link

When calling the getEnclosingClass() on a nested class, the supplied class is the correct class, though it does not expose any of it's members.
image

There is a workaround for this. Namely that you have to load in the class file manually.
image

I've validated that these are the same classes.

With a small test setup, I could not reproduce this behavior.
That made the test setup even stranger.

I'm using this functionality to create an ImportOption that filters out generated files (need to analyze the EnclosingClass for an annotation....)

@hankem
Copy link
Member

hankem commented Dec 19, 2023

I don't know what location in your new ClassFileImporter().importLocations(List.of(location)) is, but could it be that you're indeed only importing the nested class?

It's expected that ArchUnit, when dealing with missing classes that are referenced by imported classes, but not imported themselves, may create stub JavaClasses, which will have isFullyImported()==false.

Maybe you can Configure the resolution behavior according to your needs?

@codecholeric
Copy link
Collaborator

Did this help you @erikmaas-malmberg ?

@erikmaas-malmberg
Copy link
Author

Sorry for the late answer. The reminder emails were filtered into the wrong folder in my mailbox....

The Class we are asking the enclosing class for is a class that lives inside the class.
The locations is a complete folder.
This means that the relevant classes should be loaded, and thus my idea that this is a bug.

The usecase for my to do this is:

public class A {
  // .....
  static class B {
    // ....
  }
}

As both classes A and B are generated, I do want to exclude them from certain tests.
They are not in seperate packages. This to keep the code clean.
The way I can identify those classes are with certain annotations on class A.
This means that I need to check class A for this annotation while checking whether I need to check class B.

Because of this usecase I would assume that the encolosing class is on the classpath, and I have verified that it is inside the ClassFileImporter's locations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants