JavaMultipleMethod mismatch for Interface arguments
See original GitHub issueJavaMultipleMethod resolves to a wrong method signature in a case where matching should be done by the interfaces. Consider the following Cipher.init:
Cipher = autoclass("javax.crypto.Cipher")
SecretKeySpec = autoclass("javax.crypto.spec.SecretKeySpec")
default_key = [0x00] * 16
secret_key_spec = SecretKeySpec(default_key, "DESede")
# The signature we want is (int, java.security.Key) [Key is interface]
# the signature this resolves is (int, java.security.Certificate)
# JavaException: Invalid instance of u'javax/crypto/spec/SecretKeySpec' passed for a u'java/security/cert/Certificate'
cipher.init(Cipher.DECRYPT_MODE, secret_key_spec)
A (temporary) solution would be manually pull out the correct underlying call signature from JavaMultipleMethod
object using the interface name in the signature. However is this possible? I did not find any examples doing this and my poking from console did not yield results.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Java Generics Argument Type mismatch going from class ...
Short answer: Don't use a generic type B on that method. Details: There is no way to tell the compiler that, for a...
Read more >Why can't I refer to an interface inside of generic brackets in a ...
I believe that unless specifically specified, generics in Java are invariant, meaning that (to simplify), a List<string> does not inherit ...
Read more >Channel Protocol command in EtherChannel? is that new?
Solved: hello i've never seen the "channel protocol lacp/pagp" command before in all the study material i've seen i've seen and configured EtherChannels ......
Read more >Develop code that makes proper use of type parameters in ...
A generic class/interface is declared by putting type parameters after the name of the ... Type mismatch: cannot convert from Basket<Fruit> to Basket<Apple> ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a workaround, does it work if you cast it? i.e.
cipher.init(Cipher.DECRYPT_MODE, cast('java.security.Key', secret_key_spec))
This is a) still broken and b) still works with the workaround (which ironically was exactly the same Java classes despite me not including them in the Google search…) Given that my Java is non-existent though, can’t help with this one 😦
Edit: unfortunately this doesn’t work for decryption; passing the argument cast as a java.security.Key leads to a JavaException that an RSA key is needed, while passing the argument cast as an RSA key gets you back to choosing the wrong method (expecting a Certificate). Is there a way to force access to the right method? It’s annoying that I can call the right method (with the wrong arguments); I just can’t get the right method (which I could then call with the right arguments)…