Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译build时空指针 #1

Closed
beichenhpy opened this issue Mar 29, 2021 · 7 comments
Closed

编译build时空指针 #1

beichenhpy opened this issue Mar 29, 2021 · 7 comments

Comments

@beichenhpy
Copy link

环境

MacBook Air (M1, 2020) MacOs 11.2.3
maven 3.6.3
Jdk penjdk version "1.8.0_282"
OpenJDK Runtime Environment (Zulu 8.52.0.23-CA-macos-aarch64) (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (Zulu 8.52.0.23-CA-macos-aarch64) (build 25.282-b08, mixed mode)
编译器:idea 2020 3.2

运行代码

使用example编译运行,idea提示空指针异常
WX20210329-132223@2x

@ychost
Copy link
Member

ychost commented Mar 29, 2021

IDEA 配置下,setting->build->compiler->Shared build process VM options: -Djps.track.ap.dependencies=false
另外手工编译下 example 看看

@beichenhpy
Copy link
Author

IDEA 配置下,setting->build->compiler->Shared build process VM options: -Djps.track.ap.dependencies=false
另外手工编译下 example 看看

重新mvn compile整体后,可以运行了,谢谢

@beichenhpy
Copy link
Author

IDEA 配置下,setting->build->compiler->Shared build process VM options: -Djps.track.ap.dependencies=false
另外手工编译下 example 看看

还有个问题,如果使用新的maven工程,不添加任何配置,还是空指针异常
使用-Djps.track.ap.dependencies=false后报错

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: [FastAop] class java.lang.Object.aopTest not found
	at org.fastlight.apt.model.MetaMethod.getMethod(MetaMethod.java:137)
	at org.fastlight.apt.model.MetaMethod.patchedByReflectMethod(MetaMethod.java:144)
	at org.fastlight.apt.model.MetaMethod.create(MetaMethod.java:74)
	at RealService.<clinit>(RealService.java:3)

具体代码如下
RealService

import org.fastlight.aop.annotation.FastAspect;

public class RealService {
    @FastAspect
    public void aopTest(){
        System.out.println("正在运行");
    }

    public static void main(String[] args) {
        new RealService().aopTest();
    }
}

FastAspectDo

import org.fastlight.aop.annotation.FastAspectMark;
import org.fastlight.aop.handler.FastAspectHandler;
import org.fastlight.aop.model.FastAspectContext;

@FastAspectMark
public class FastAspectDo implements FastAspectHandler {
    @Override
    public boolean support(FastAspectContext fastAspectContext) {
        return true;
    }

    @Override
    public void preHandle(FastAspectContext fastAspectContext) {
        System.out.println("方法执行前");
    }

    @Override
    public void postHandle(FastAspectContext ctx) {
        System.out.println("方法执行后");
    }

    @Override
    public int getOrder() {
        return 1;
    }
}

@beichenhpy
Copy link
Author

字节码文件

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import org.fastlight.aop.annotation.FastAspect;
import org.fastlight.aop.handler.FastAspectHandler;
import org.fastlight.aop.handler.FastAspectSpiHandlerBuilder;
import org.fastlight.aop.model.FastAspectContext;
import org.fastlight.apt.annotation.FastMarkedMethod;
import org.fastlight.apt.model.MetaAnnotation;
import org.fastlight.apt.model.MetaClass;
import org.fastlight.apt.model.MetaMethod;
import org.fastlight.apt.model.MetaParameter;
import org.fastlight.apt.util.FastMaps;

public class RealService {
    private static MetaMethod[] __fast_meta_cache = new MetaMethod[]{MetaMethod.create(0, "aopTest", MetaClass.create("java.lang.Object", new MetaAnnotation[0]), new MetaParameter[0], new MetaAnnotation[]{MetaAnnotation.create(FastAspect.class, FastMaps.newHashMapWithPair(new Object[]{"builder", FastAspectSpiHandlerBuilder.class}))}, FastMaps.newHashMapWithPair(new Object[]{"fast.meta_handler_builder_class", FastAspectSpiHandlerBuilder.class}))};

    public RealService() {
    }

    @FastMarkedMethod(0)
    public void aopTest() {
        FastAspectContext __fast_context = FastAspectContext.create(__fast_meta_cache[0], this, new Object[0]);
        FastAspectHandler __fast_handler = __fast_context.buildHandler();
        boolean __fast_support = __fast_handler.support(__fast_context);
        if (__fast_support) {
            __fast_handler.preHandle(__fast_context);
            if (__fast_context.isFastReturn()) {
                return;
            }
        }

        try {
            try {
                System.out.println("正在运行");
                return;
            } catch (Throwable var8) {
                if (__fast_support) {
                    __fast_handler.errorHandle(__fast_context, var8);
                    if (__fast_context.isFastReturn()) {
                        return;
                    }
                }
            }

            throw var8;
        } finally {
            if (__fast_support) {
                __fast_handler.postHandle(__fast_context);
            }

        }
    }

    public static void main(String[] args) {
        (new RealService()).aopTest();
    }
}

@ychost
Copy link
Member

ychost commented Mar 29, 2021

看了一下,应该是你的 RealService 没有 package,所以在处理的时候关联到了 java.lang.Object package 下面去了,这个我回去修下,测试的时候主要是测 lambda、内部类、内部动态类、方法内部类这些情况,对于 package 这块确实没测

@beichenhpy
Copy link
Author

看了一下,应该是你的 RealService 没有 package,所以在处理的时候关联到了 java.lang.Object package 下面去了,这个我回去修下,测试的时候主要是测 lambda、内部类、内部动态类、方法内部类这些情况,对于 package 这块确实没测

是的,辛苦

@ychost
Copy link
Member

ychost commented Mar 30, 2021

已修复

@ychost ychost closed this as completed Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants