fail to redefine "java.io.ObjectInputStream" with ByteBuddy? - byte-buddy

Fail to redefine java.io.ObjectInputStream with ByteBuddy.
I have tried many ways to solve this problem. But I can not find methods to hook "java.io.ObjectInputStream$resolveClass".May you help me?
new AgentBuilder.Default()
// .ignore(none())
.type(named("java.io.ObjectInputStream"))
.transform((builder, typeDescription, classLoader,module) ->
builder.method(named("resolveClass"))
.intercept(MethodDelegation.to(TimerAdvice.class)))
.with(AgentBuilder.Listener.StreamWriting.toSystemOut())
.with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.installOn(inst);

Your MethodDelegation would invoke a suitable method in TimerAdvice. For this to be possible that class would need to be loaded on the bootstrap class loader. Is this the case in your scenario?
Alternatively, look into using Advice for decorating a method.

Related

How can I navigate to Lombok generated implementations

I'm wondering if it would be possible to navigate directly to the methods generated by Lombok using Intellij IDEA.
For instance, for this given example:
#Builder
public class AClass {
private String body;
}
trying to go to the implementation of AClass#builder in an instruction like AClass.builder().build() results in Intellij navigating to AClass, instead of taking me to the real compiled method, which is generated under target directory
Please feel free to create an issue here: https://youtrack.jetbrains.com/issues/IDEA
Currently you can't change the behavior.

Swift init with closures is not visible in Objective C

My swift custom initilizer with closure is not visible in the objective c code.
init(url:String,request:ABaseRequest,
type:AnyClass, success:(ABaseResponse)->Void,
failure:(ResponseCode,NSError)->Void) {
......
......
}
where as init without closure is visible
init(url:String,request:ABaseRequest,type:AnyClass) {
......
......
}
Do you guys know how to solve this issue?
After inspecting whole code I found the problem in my code. A class used inside my closure is not annotated with #objc ! . So be careful guys, each and every classes that is going to be exposed to objective c should be annotated with #objc. Thanks.
By now you may have already solved the problem. I've run into a similar one myself.
Unless there are other problems, the visibility issue can be fixed by trying to build the project. If you introduce something new in your Swift code, it may not be immediately visible to Objective-C code, but building the project should fix it.
If there is another problem related to your custom initializer, the compiler will tell you when you try to build. If that is the case, share the problem here.

Easy way to tell if a method is overriding another method?

I'm just beginning with ObjC. I'm wondering how to find out when looking at code, written by me or from a template that comes when you use the wizard to create a new class, how you can tell if a method is overriding something.
In Java, you can mark a method with #Override, and then it's very easy to see if it's overriding something. That's not foolproof, because #Override is optional, but if I'm still unsure I can just type that in and see if it generates an error.
Is the only way to look up the source of the superclass, or in the case of a framework to read the documentation?
I don't know a way to see this immediately, but you could check if super responds
to the same selector. Example:
- (void)myMethod
{
// Temporarily add this line. If the compiler does NOT complain,
// "myMethod" overrides a method from some superclass.
[super myMethod];
// ...
}
You can use instancesRespondToSelector to see if your instance has an implementation of the method in its object hierarchy.
[MyClass instancesRespondToSelector:#selector(myMethod)];
or depending on what type of checking you need to do
[MyClassSuperClass instancesRespondToSelector:#selector(myMethod)];

Flex Interface method createAutomationIDPartWithRequiredProperties error

I'm currently creating a class that extends UIComponent in Flex 3, but when the flash builder try to compile show me some errors
1044: Interface method createAutomationIDPartWithRequiredProperties in namespace mx.automation:IAutomationObject not implemented by class components:ArtWorkImage
1044: Interface method get automationEnabled in namespace mx.automation:IAutomationObject not implemented by class com.senocular.display:TransformTool
I see that UIComponent implements this interface, but I had never had this error before, I'm assuming UIComponent should made this implementation by default, so it should be something else, I already try to recreate the project or clean it, with no result, can someone please point me how maybe this can be fix, thanks for your help
oh btw I had this project before in flex builder, exported as a FXP and imported in Flash Builder, thanks!
All UI objects use an Automation delegate to handle implementation of the automation interface. Each UIComponent has a specific automation delegate registered with the Automation Framework. These automation delegate implementations are injected into the object by the Automation framework when the object is created according to the class name of the object.
For example:
UIComponent <- UIComponentAutomationImpl
ToolTip <- ToolTipAutomationImpl
DateChooser <- DateChooserAutomationImpl
Normally if you subclass a component you should inherit the Automation Implementation. However depending upon how the instances of the object are being created the automation framework may not be able to resolve the class name to the appropriate super class. In this case you may need to take additional steps to get the automation implementation into your class.
If you want your class to automatically be injected with a particulary automation implementation you should call the static registerDelegateClass method on the mx.automation.Automation class.
import mx.automation.*
Automation.registerDelegateClass(com.foo.bar.ArtWorkImage, mx.automation.delelegates.core.UIComponentAutomationImpl);
Alternatively you could directly implement the IAutomationObject methods in your UIComponent or create your own delegate class and instantiate and "inject" it into your class in its' constructor thereby by passing the Automation framework.
Here are few links that might help you understand the automation framework:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/Automation.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/delegates/core/UIComponentAutomationImpl.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/package-detail.html

SuppressMessage in interface

I tried to suppress a particular FxCop warning for a method defined in an interface by adding SuppressMessage attribute to the method. But the warning still appears. I know the SuppressMessage attribute is the right choice.
public interface ICustomerAccess
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design",
"CA1024:UsePropertiesWhereAppropriate",
Justification = "This method involves time-consuming operations", Scope="member")]
IList<ICustomer> GetCustomers();
}
Does anyone have the experience on suppressing FxCop warning in an interface?
Thanks,
H
For the record, the answer is in the question's comments:
#Angelina said: Thank you very much! I
am able to resolve the issue by adding
CODE_ANALYSIS to the project.