Specify class loader for loading dependencies of an advice's dependency - byte-buddy

I have an advice class that makes use of another class that's part of the agent jar, but this other class has a dependency on a class that's not present in the agent jar. This class that's not present in the agent jar is present in another jar that's on the application class loader. The agent jar is on the system class loader. So I run into NoClassDefFoundError. I have tried using Transformer.ForAdvice as suggested in this other post, but that only works for the advice class.
// In agent jar on system class loader
MyAdviceClass {
#Advice.OnMethodEnter
public static void onMethodEnter() {
YetAnotherClass.doSomething(); // works fine as Transformer.ForAdvice makes use of the correct class loader while inlining this code
AnotherClass.doSomething(); // NoClassDefFoundError happens inside this method call
}
}
// In agent jar on system class loader
public class AnotherClass {
public static void doSomething() {
YetAnotherClass.doSomething(); // NoClassDefFoundError happens here because the system class loader is used to load YetAnotherClass, but that class is only present on the application class loader
}
}
// In user jar on application class loader
public class YetAnotherClass {
public static void doSomething() {
// do something else
}
}
Transform looks like this:
.transform(new AgentBuilder.Transformer
.ForAdvice()
.include(getClass().getClassLoader())
.advice(methodMatcher, "com.something.advice.MyAdvice.class"));
MyAdviceClass and AnotherClass are present in the agent jar. YetAnotherClass is present in user jar that's not on the system class loader, its on the application class loader. How can I solve this problem? i.e. is there a way by which I can force the use of the application class loader in AnotherClass?

I assume that AnotherClass is not visible from the class being instrumented. In this case, you should not include the class in ypur agent jar but place it in a seperate jar that you append to the boot loader via Instrumentation.appendToBootSearchPath. Classes on the boot loader are universally visible and should therefore be accessible to your instrumented class.
If the injected classes reference classes of the instrumented class loader you might however need to inject classes into the class loader using a ClassInjector.

Related

PHP/Laravel can not resolve parent Class

Using php 7, Laravel 5.5. All models are in default app/ folder, Prototype is in app/ folder too. Nothing was moved
What is most frustrating - this worked all right for controllers (everything is in their default folders)
My Prototype Class:
class Prototype extends Model
{
//other code
}
My child Class:
class Tree extends Prototype
{
//other code
}
Exception:
include(/var/www/html/app/Prototypephp): failed to open stream: No such file or directory
I need help to fix this issue. Thanks!
After a few hrs of working over this issue solved it by moving Prototype Class to other namespace (and folder). Did the same to PrototypeController for code readability.

How can I execute a terminal command when opening IntelliJ Project?

Not even sure if this possible with IntelliJ but I'd like to tie the vagrant up command to run automatically when I open an IntelliJ project. I've scoured the settings but haven't been able to find anything that gives me this functionality.
You can write a plugin.
https://www.jetbrains.com/help/idea/plugin-development-guidelines.html
Define an application component in the plugin.xml
<application-components>
<component>
<implementation-class>com.steve.plugins.recentprojects.RecentProjects</implementation-class>
</component>
</application-components>
And then you implement ApplicationComponent, which defines these methods in a parent interface:
public interface BaseComponent extends com.intellij.openapi.components.NamedComponent {
default void initComponent() { /* compiled code */ }
default void disposeComponent() { /* compiled code */ }
}
It seems like initComponent() can be a nice place to insert a function to start vagrant.
Alternatively... externalise the startup, write a script that starts vagrant and then starts intellij...

Override Prestashop Core controller using a module

Working on a project that consist to create thumbs for the product's features,
is there a way to override the core controller *AdminFeaturesController*using a module?
In your module you can create a /override directory. Under this directory you will create this file /override/controllers/admin/AdminFeaturesController.php.
This file should look as follow:
<?php
class AdminFeaturesController extends AdminFeaturesControllerCore
{
// Only override the functions that should be modified
public function function_that_i_want_to_override() {
}
}
The override will be effective after module installation.

Shared base controller between modules

I am setting up a multi-module application, so far I have it setup like this example http://docs.phalconphp.com/en/latest/reference/applications.html.
But I was wandering if its possible to have shared base controller that both the backend and frontend controllers extend from. This is so I can have a single ACL in the base controller. How would I set that up?
According to the docs I can create a controllerbase anywhere and then just require this file directly in the bootstrap file or cause to be loaded using any autoloader. So I created a folder called apps/shared/controllers/ControllerBase.php and required this file directly in the bootstrap file but this does not work.
If I try to load a controller like so:
class AdminController extends ControllerBase
{
public function indexAction()
{
echo "<h1>Hello admin!</h1>";
}
}
I get an error ...Backend\Controllers\ControllerBase' not found in......
So how do I cause to be loaded using any autoloader as per the docs? Do I need to register it as its own namespace or something?
You not using the full namespace path for your base controller so the autoloader attempts to find it under in the same namespace of the child class.
Try something like this:
namespace MyApp\Backend\Controllers;
use MyApp\Shared\Controllers\ControllerBase;
class AdminController extends ControllerBase
{
public function indexAction()
{
echo "<h1>Hello admin!</h1>";
}
}
This answer consider that you have applied the PSR-0 and PSR-4 properly.

The hierarchy of the type AddEntryAction is inconsistent (Jface)

i have the following class in eclipse
class AddEntryAction extends Action {
public AddEntryAction() {
super("Add Entry");
setToolTipText("Add Entry");
}
public void run() {
WizardDialog dlg = new WizardDialog(MainClass.mainWindow.getShell(),
new AddEntryWizard());
dlg.open();
}
}
and Action class extends AbstractAction which intern extends EventManager class. Both these parent classes are part of the eclipse SWT/jface libraries... I get the following error on the above class declaration
The project was not built since its
build path is incomplete. Cannot find
the class file for
org.eclipse.core.commands.common.EventManager.
Fix the build path then try building
this
project DisplayExample Unknown Java
Problem
The type
org.eclipse.core.commands.common.EventManager
cannot be resolved. It is indirectly
referenced from required .class
files MainClass.java /DisplayExample/src line
94 Java Problem
AddEntryAction is declared within the same source file MainClass.java. Actually, this is an example from Java2s.com ... I have the libraries/jars because i can see the compiles classes of all these clases
The error "The project was not built since ... org.eclipse.core.commands.common.EventManager cannot be resolved..." with swt/jface dependencies can be caused by missing reference sources or binaries containing org.eclipse.core packages in addition to org.eclipse.swt and org.eclipse.jface packages.
E.g. build path in my case included:
swt.jar
org.eclipse.jface_3.4.2.M20090107-0800.jar
Following jar was missing and caused above error:
org.eclipse.core.commands_3.4.0.I20080509-2000.jar