-
Notifications
You must be signed in to change notification settings - Fork 34
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
False positives when using java.util.Random with JDK 17-ea17 #177
Comments
Note: Upgrading to forbiddenapis 3.1 doesn't solve the problem. |
Hi, this is a bug in forbiddenapis, triggered by the following commit in openjdk: openjdk/jdk@a0ec2cb#diff-fdfca19a8fa8e73366160f4afaf99a1ded21423338d18b71662eda1be8c933d4R88 It will affect all code that accesses java.util.Random. The reason for this is that forbiddenapis goes up the class hierarchy to find all superclasses and superinterfaces. Unfortunately, I think I have to add a stop condition to class hierary climbing at the place where it enters JDK-internal code. |
Sorry there's no workaround at the moment except adding a Suppress directive or downgrading JDK. The Lucene team haven't seen that up to now, as we are still on build 16. |
Hi! No problem, thanks for the fast answer. I'll disable forbiddenapis when building on JDK 17+ for now; JDK 17 is experimental anyway :) |
I will do my best to fix this problem. The class hierarchy climbing was always some problematic part as it may lead to "false positives" (although correct detections), because the user does not expect the problem. I will also update to latest ASM and add signatures for JDK-16 soon. So a fix is close, because I had no time for a specific JDK-16 release yet, so it's a good time to include that fix. |
Hi, You are using the static file "jdk-internal-1.8". This file contains an explicit signature I can for sure fix the problem with A quick workaround for you would be to use So there's a dilemma. |
FYI, there's a small problem in your POM file: Since forbiddenapis 3.1, there's a new setting To fix the POM file, i'd suggest to set release/target/source version in the properties to 8 and remove the explicit declaration in the plugin config. |
Thanks for the tip. Regarding the signature files... I imagine In my actual project (Hibernate Search) I actually use |
Yes that's true. Unfortunately, the current problem also happens with
Yes its a duplicate, but won't fix your issue :-) |
FYI, I also found a problem in JDK 17 class library and opened a bug report. This is not dircetly causing this issue, but I found it by accident when writing test cases: https://bugs.openjdk.java.net/browse/JDK-8265137 |
There is now a PR: #178 I need to add a test. It consists of 2 commits: first is to rewrite the whole logic behind the class hierarchy to use a "visitor" pattern. In a second commit just a few checks are added: accce12 Basically: If some code from inside the runtime extends/implements some non-portable class/interface, this is ignored and neither method calls nor field accesses are recognized. This is still a hack, but looks useable. |
Hi, In the meantime, the APIs of Random were revised, as the JDK developers figured out that having some hidden base class in the class hierarchy is a bad idea, as it suddenly changes pblic API of Random, ThreadLocalRandom and others. Therefor they moved the internal implementations to a private class with static utility methods:
Once this is part of JDK, the problem should automatically disappear. Nevertheless, I'd like to push the changes in the PR, but it is hard to find a good test case (you cannot mock or synthesize one, as it relies on classes be inside the JDK runtime - which may change all the time (like in the fixes coming to OpenJDK 17 soon). I will think about it a few more days and then decide how to handle that. |
Running the forbidden-apis Maven plugin with JDK 17-ea17 leads to false positives.
Apparently, uses of allowed classes are mistaken for uses of their (forbidden) inner classes, leading to
For example, I created a reproducer using
java.util.Random
, with forbiddenapis configured to forbid the bundled signaturesjdk-internal-1.8
.Everything should work fine, but when running with Maven 3.6.3 and JDK 17-ea17, we get an error stating "Forbidden class use: jdk.internal.util.random.RandomSupport$AbstractSpliteratorGenerator", even though that class is never used in the source code.
Full output:
For reference, it used to work with JDK 17-ea13:
I suspected that JDK17 might have introduced some cutting edge magic that inlines constructors somehow, but apparently not: decompiling the class files with CFR yields the original source code.
So I suspect forbiddenapis may be doing something that doesn't work with JDK17-ea17 anymore.
Decompiling the file that triggers the error shows that it's not some cutting edge JDK17 magic
The text was updated successfully, but these errors were encountered: