-
Notifications
You must be signed in to change notification settings - Fork 300
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
Volatile should also be applicable to Java Methods #212
Comments
Not allowing
|
Is there a way to filter them out in ArchUnit? The reflect of both methods return the same |
I also noticed that sometimes the reflect for the 2 JavaMethod instances returns the method that has the volatile modifier and sometimes not. I get different results in different executions. |
As @hankem pointed out, by the JLS there is no For now I think you have no other choice than to use reflection What I'm a little puzzled about though, is that you say
so it falls back to the reflection API, and if you look at the explanation about bridge methods, a bridge method should not have the same signature as the concrete method. I.e. the bridge method has the signature of the raw type, the concrete method of the type parameter, I don't see, how that could fall together? Maybe you can provide a quick example so I could check it out? |
I'll try to create a test case later this week. ArchUnit detected 2 JavaMethod for my class with exact same parameters, name, etc. |
As promised, this is the failing test case:
Instead of getting 1 failure (for
While debugging I noticed the created JavaMethod for The difference from the method and its bridge is the return type: Foo and AbstractFoo, respectively |
Hmm, this is really weird, because this test does behave differently when I execute it, I only get one (correct) failure and when I look at the bytecode, I see
I.e. the synthetic method has the same annotation as the overridden method. This might be JDK specific, I compiled it with an Oracle JDK 10 and an Open JDK 11 and got the same result though. It seems to me, that what you get when you call |
I'm using oracle Java 8 in Windows 10 (work env). I'll update you with the exact version later today. I'm compiling and running it inside eclipse 2018-09 if I'm not mistaken. It might well be that eclipse compiler doesn't annotate the bridge method. Anyway I'll give you more info later today |
So, my environmnet is:
The compiled class (Using eclipse compiler)
|
Looks like good ol' JDK 8 does not put |
I'm not sure if this is related to #87
I noticed that several methods that are actually in an abstract super class was appearing in one of my tests as they were in the subclass. After some investigation I noticed that all these methods are marked as "volatile" by java reflect (
Modifier.isVolatile()
) but the JavaModifier from ArchUnit wasn't showing them as "volatile". It seems that ArchUnit only allow volatile at the field level:VOLATILE(EnumSet.of(ApplicableType.FIELD), Opcodes.ACC_VOLATILE),
The only way to filter them out from my tests was to create a predicate that does a reflect and use standard java reflect API to check the modifiers (which cause the test to be much slower).
The text was updated successfully, but these errors were encountered: