0

I'm writing CRaSH plugin, which in Java looks like

public class AuthPlugin extends CRaSHPlugin<AuthenticationPlugin> implements AuthenticationPlugin<String> {


@Override
public String getName() {
    return "auth";
}

@Override
public Class<String> getCredentialType() {
    return String.class;
}

@Override
public boolean authenticate(String username, String credential) throws Exception {
    System.out.println("authenticate " + username + " : " + credential);
    return false;
}

@Override
public void init() {
    System.out.println("init");
}

@Override
public AuthenticationPlugin getImplementation() {
    return this;
}
}

However, I want to express this class in Kotlin. And the problem is AuthenticationPlugin which has generic parameter. Omitting is causes Kotlin compilation to fail, so I used star projection, like

class AuthPlugin : CRaSHPlugin<AuthenticationPlugin<*>>(), AuthenticationPlugin<String> {

override fun getImplementation(): AuthenticationPlugin<String> = this

override fun getName(): String = "auth"

override fun authenticate(username: String?, credential: String?): Boolean {
    println("authenticate  ${username}, ${credential}")
    return true
}

override fun getCredentialType(): Class<String> = String::class.java
}

which compiles fine, but unfortunately, CRaSH seems to use it's own way of loading plugins, and I got runtime exception

Caused by: java.lang.UnsupportedOperationException: Type resolution of org.crsh.auth.AuthenticationPlugin<?> not yet implemented
at org.crsh.util.Utils.resolveToClass(Utils.java:576) ~[crash.shell-85c8d21173b71a0275b599a3a4444723dd64c6af.jar:?]
at org.crsh.util.Utils.resolveToClass(Utils.java:560) ~[crash.shell-85c8d21173b71a0275b599a3a4444723dd64c6af.jar:?]
at org.crsh.plugin.CRaSHPlugin.<init>(CRaSHPlugin.java:59) ~[crash.shell-85c8d21173b71a0275b599a3a4444723dd64c6af.jar:?]

Indeed, the input to resolveToClass() is "Class@interface org.crsh.auth.AuthenticationPlugin" for Java version, while for Kotlin its "ParametrizedTypeImpl@org.crsh.auth.AuthenticationPlugin". I assume CRaSH loader cannot handle this properly. I can of course just use Java, but for the sake of sticking to Kotlin - how can I make this class to compile to exactly the same type as the Java version and make it loaded properly by CRaSH?

M4ks
  • 11,744
  • 7
  • 27
  • 48
  • I think > will work fine for you right? – Sangeet Suresh Oct 27 '17 at 10:37
  • Not really - it results in ```used by: java.lang.UnsupportedOperationException: Type resolution of org.crsh.auth.AuthenticationPlugin not yet implemented at org.crsh.util.Utils.resolveToClass(Utils.java:576)``` – M4ks Oct 27 '17 at 10:49

0 Answers0