question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JavaMultipleMethod mismatch for Interface arguments

See original GitHub issue

JavaMultipleMethod 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.

<bountysource-plugin> --- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/31513645-javamultiplemethod-mismatch-for-interface-arguments?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github). </bountysource-plugin>

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kivedcommented, Mar 3, 2016

As a workaround, does it work if you cast it? i.e. cipher.init(Cipher.DECRYPT_MODE, cast('java.security.Key', secret_key_spec))

0reactions
gbm001commented, Oct 29, 2018

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)…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found