XXXX (Class Name) does not implement inherited abstract member
'SecurityToken.SecurityKeys.get'
Tried implemented override method. But still throws error
Related
I have an activity that implements a listener with a generic type that requires me to implement the onResponse function.
The listener is defined in the following format:
public interface ListenerClass<T> {
onResponse(T type)
}
And my activity implements it using T == ModelClass.
class MyActivity : ListenerClass<ModelClass> {
(...)
override fun onResponse(response: ModelClass) {
(...)
}
}
The listener is part of an SDK so I cannot change any code in there. They use a piece of reflection to get the type of my 'ModelClass' using the following code:
listener.getClass().getDeclaredMethods()[onResponseIndex].getParameterTypes()[0]
The result of this code should be Class<ModelClass> but I get Class<Object>. I found out that when I call the code above on a Java class, I get the correct result, but my activity is written in Kotlin.
1) How can I get the parameter type of a kotlin function using reflection?
2) If I have an answer to question 1 I still won't be able to change the SDK's code. Is there anything I can write in my Kotlin code that makes the piece of code above find the correct parameter class type?
Please read along. I have a Lion class that has a method stayLion.
public class Lion {
//class Variables and methods
public void stayLion(String temp,int temp2,double temp3, boolean temp4,Food food) throws InterruptedException {
//method Body
}
}
The method takes in a Food instance as one of its parameter. Food class has cook method
public class Food{
public void cook(){
}
}
I am trying to instrument both these methods, stayLion and cook. The transform method is called for every class that is loaded by JVM.(Interesed to know, where and who calls it. Correct me if I am wrong) If classname matches with my desired list of classnames, I extract the list of methods, and verify the methodName and its parameter, I find the CtMethod instance for the method I wish to instrument (stayLion and cook).
public byte[] transform(ClassLoader loader, final String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
//verifying className(fully qualified), if same then,
ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.getCtClass(className.replace("/","."));
CtMethod[] methods = ctClass.getDeclaredMethods();
for (CtMethod method : methods) {
//verifying method (name and parameter)
method.insertBefore( //some code );
}
}
However, in the process of verifying parameters for stayLion, the Food class gets loaded and transform method is not called, (I don't know the reason for this. The class loader is same. Why is transform method not called for Food class as it gets loaded?). To overcome this, I explicitly call transform method for Food class (in general, I call transform method everytime a class whose method I wish to instrument is in the parameter list of any other method I also wish to instrument).
transform(loader,"com/here/debugHelper/Food",null,protectionDomain,null);
But this explicit calling of transform method is ineffective. To be precise,
ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.getCtClass(className.replace("/","."));
CtMethod[] methods = ctClass.getDeclaredMethods();
Till here, methods contains list of all methods of Food class. After verifying cook method with no parameter
for (CtMethod method : methods) {
//verifying method (name and parameter)
method.insertBefore( //some code );
}
But at this point, method.insertBefore() is ineffective and is not adding any code to the desired method.
The transform method is invoked by the JVM during class loading or redefinition. It does not make much sense for you to call the method directly unless you are testing.
If you are loading a class during a code manipulation, no class being loaded will be transformed. This is to avoid circularities in your instrumentation where instrumenting Aloads B and instrumenting B loads A. If you attempt to load the instrumented class itself, this will result in a ClassCircularityError.
I assume that when you instrument Lion, you are loading Food when processing the parameters. By using Javassist, you normally avoid this as Javassist loads class files directly but I figure that you are referencing the Lion class as a constant somewhere and therefore load it somwhere in your transformer.
I have a custom class for holding a collection of data.
I use this class throughout my code, and it works without a hitch, except for in one place, when I need to pass the class object to a method. Here is some very basic code to demonstrate what I am seeing.
public class doSomething
static void myMethod(customClass_myItem) {}
public class customClass
public str classMethod() {}
form method
customClass myItem = new customClass();
myItem.classMethod(); //this works, so I know the class is good
doSomething::myMethod(myItem); //Gives error: variable is not of the type CLASS.
I am completely lost here. If I couldn't use the class at all, I would understand, but with it not working when passed to another method.. doesn't make any sense. If I put in a breakpoint, the debugger indicates myItem is a class of the correct type.
Any suggestions?
Thanks
Your myMethod expects an object of class customClass_myItem (or a descendant) not customClass.
If you change your parameter type to object it should work.
static void myMethod(Object o) {}
I'm building a small application with Nancy
I want to have a kind of base class, that other modules can inherit from.
See below (there is a reason this isn't an abstract class, which I'll explain below)
public class ImportModule<T> : NancyModule
{
protected ImportModule()
: this(typeof(T).Name.ToLower())
{
Get["/"] = _ => "need to select an action - xxx";
Get["/importnew"] = _ => ImportNew(); //note - method omitted for brevity
}
}
When I run my app, I get
Unable to resolve type: My.NameSpace.TypedImporter`1
As a sidenote, if the ImportModule class is abstract, this doesn't happen
Ok-
Now, I could have a class like this:
public class MyCustomImporter : ImportModule<MyCustomType>
{
//overrides....
}
But, elsewhere, in a "DefaultImportModule" I have the following:
var importerModule = Activator.CreateInstance(typeof(ImportModule<>).MakeGenericType(type));
So I need to be able to create a type of importer, based on a type that's passed in
(Basically, if a user hits the url /customer, it's doing the same as a class like this would)
public class CustomerImporter : ImporterModule<Customer>
{
}
So, as I see it, I have two choices:
1) Stop nancy trying to map my ImportModule
2) Instantiate a "phantom class" that inherits from ImportModule and make ImportModule abstract again
There is a discussion in the Nancy group that may be related to your problem, it is certainly related to the non-abstract base modules not being recognised by Nancy. Here is what Andreas HÃ¥kansson had to say:
Nancy locates everything that's inheriting NancyModule and assumes
it's something it can instantiate. Nancy is aware that it cannot
create an instance of an abstract module. So if you have a base-module
that's not abstract then Nancy will attempt to new it up. I'd like to
think that for 99% of the time, having a non-abstract base class is a
broken design.
And here is the link to the discussion:Unable to resolve type: Nancy.Routing.DefaultRouteResolver
Even though I have specified the scope type as method, it gets instantiated in CONVERSATION scope.
>
UserHome userHome = (UserHome) Component.getInstance(UserHome.class, ScopeType.METHOD);
This is quite confusing, can someone explain this behavior?
When you call
Component.getInstance(UserHome.class, ScopeType.METHOD);
Seam internal behavior is to call
Object result = Contexts.lookupInStatefulContexts(name);
lookupInStatefulContexts API says
Search for a named attribute in all contexts, in the following order: method, event, page, conversation, session, business process, application.
As your ScopeType.METHOD does not contain your UserHome.class component, The search go on until get its scope (StypeType.CONVERSATION, right ?)
UPDATE
I was under the impression that if you specify the ScopeType to getInstance method you will be able to create the object within that scope
If the target component does not have the desired scope associated, getInstance method does not create the component within that scope. Instead it performs a hierarchical search by using Contexts.lookupInStatefulContexts till get some assigned scope
If you want more than one scope can be assigned to a component, you must scecify it by using #Role (#Roles) annotation
#Name("user")
#Scope(ScopeType.EVENT)
#Role(name="loggedUser", scope=ScopeType.SESSION)
public class User { ... }
So you specify the desired scope
Component.getInstance(User.class, ScopeType.EVENT);
or
Component.getInstance(User.class, ScopeType.SESSION);
remember Seam performs lookup by field/property name
private #In User user; // Take ScopeType.EVENT as scope
private #In User loggedUser; // Take ScopeType.SESSION as scope
I assume your UserHome class extends Seam's EntityHome class. The super class of EntityHome, which is Home, is in scope ScopeType.CONVERSATION:
#Scope(ScopeType.CONVERSATION)
public abstract class Home<T, E> extends MutableController<T>
Either you did not override the scope in your UserHome declaration or Seam ignores #Scope annotations in subclasses if one of the super classes already have an #Scope annotation.