-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8279800: isAssignableFrom checks in AlgorithmParametersSpi.engineGetParameterSpec appear to be backwards #7037
Conversation
…arameterSpec appear to be backwards 8279800: isAssignableFrom checks in AlgorithmParametersSpi.engineGetParameterSpec appear to be backwards
👋 Welcome back weijun! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, an interesting catch. I have a concern, although.
if (IvParameterSpec.class.isAssignableFrom(paramSpec)) { | ||
if (paramSpec.isAssignableFrom(IvParameterSpec.class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to cast() is confusing. But if the paramSpec is AlgorithmParameterSpec.class or Object.class, what's the expected behavior? There are potential casting exception, I guess. Maybe, a exactly class matching could be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, then the if
block will be true and the spec object is casted to your specified class (AlgorithmParameterSpec.class
or Object.class
) and it always succeeds.
This is exactly what I want to achieve. In fact, this bug and the other getInstance(oid)
bug have the same root. I was trying to decode an algorithm identifier from its encoding. First, the encoding of the algorithm is in OID so AlgorithmParameters.getInstance()
must support OID. Second, I want to get the spec from the parameters without knowing the algorithm name and the child AlgorithmParametersSpec
class type, so AlgorithmParameters::getParameterSpec
must support AlgorithmParameterSpec.class
as the argument.
Otherwise, the program needs to know name and parameter spec type on all supported algorithms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... In hindsight, the cast call sort of confirms that the intended ordering is the suggested one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check ensures casting always succeeds. The fact that this has not been noticed for such a long time means everyone is using the exact subclass type when calling the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I suppose so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PBEKeyFactory.java, PBKDF2Core.java and PBKDF2HmacSHA1Factory.java also have isAssignableFrom() calls which seem backward. Perhaps covering them as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, then the
if
block will be true and the spec object is casted to your specified class (AlgorithmParameterSpec.class
orObject.class
) and it always succeeds.This is exactly what I want to achieve.
Unfortunately, there is a returned value that we cannot return an object of any class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, then the
if
block will be true and the spec object is casted to your specified class (AlgorithmParameterSpec.class
orObject.class
) and it always succeeds.
This is exactly what I want to achieve.Unfortunately, there is a returned value that we cannot return an object of any class.
Oh, I missed that the paramSpec should be of class T, which extends AlgorithmParameterSpec. Then, I have no more concerns.
|
||
static void test(String algorithm, AlgorithmParameterSpec spec, | ||
Class<? extends AlgorithmParameterSpec>... classes) throws Exception { | ||
var ap1 = AlgorithmParameters.getInstance(algorithm); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Print out the algorithm which has been tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can, but if an exception is thrown, I can find out which algorithm has a problem by looking at the line number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, just thought that reporting the algorithm to the test output seems more informative. Otherwise, always have to dig out the source to find out what has been covered.
…arameterSpec appear to be backwards
New commit pushed. Turns out |
@wangweij This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 101 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. Thanks~
/integrate |
Going to push as commit cb25029.
Your commit was automatically rebased without conflicts. |
Change the order so parent class is at the left.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7037/head:pull/7037
$ git checkout pull/7037
Update a local copy of the PR:
$ git checkout pull/7037
$ git pull https://git.openjdk.java.net/jdk pull/7037/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7037
View PR using the GUI difftool:
$ git pr show -t 7037
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7037.diff