TriggerReactor

TriggerReactor

24.6k Downloads

Not CATCH bug?

LimuLhw opened this issue · 6 comments

commented

Before/읽어주세요

Make sure that you have used /trg debug so that the more detailed error message will show up in the console.
신고전에 /trg debug 명령어를 사용해서 디버그 모드를 켜주세요. 그래야 콘솔창에 더 자세한 정보가 나옵니다.


Describe the bug/버그 증상
17번 라인에서 해당 파일이 없으면 java.lang.reflect.InvocationTargetException/java.io.FileNotFoundException 로 Catch 되어야 하는데 catch로 넘어가지 않은 상황입니다.

If the file does not exist on line 17, it should be caught as java.lang.reflect.InvocationTargetException/java.io.FileNotFoundException, but it is not passed to catch.

Server information/서버 정보

  1. Paper 1.16.5, Java 11 OpenJDK
  2. 3.3.0.6 - Beta

Error message/에러 메시지
If error message (in red color) shows up in Minecraft client or on the console, report it here
에러메시지 (빨간색) 가 나타났다면 클라이언트와 콘솔의 메시지를 올려주세요.
image

Others/그 밖의 정보들

[11:36:16 INFO]: Limu_lhw issued server command: /filetest //커멘드 실행 (Command Execute)
[11:36:16 WARN]: java.lang.reflect.InvocationTargetException //라인 17 Exception (Line 17 Exception)
[11:36:16 INFO]: 2 //라인 19
[11:36:16 INFO]: :/ //라인 28. finally 씬

commented

Could you show me the full error log with debug mode on?

[21:08:11 INFO]: Limu_lhw issued server command: /filetest
[21:08:11 WARN]: java.lang.reflect.InvocationTargetException
[21:08:11 WARN]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance
0(Native Method)
[21:08:11 WARN]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:62)
[21:08:11 WARN]: at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInst
ance(DelegatingConstructorAccessorImpl.java:45)
[21:08:11 WARN]: at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490
)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.tools.ReflectionUtil.constructNew(Reflec
tionUtil.java:512)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.call
Function(Interpreter.java:1179)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.inte
rpret(Interpreter.java:993)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:554)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:516)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:516)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:270)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:516)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:243)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
tWithContextAndInterrupter(Interpreter.java:186)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger.start(Trigg
er.java:270)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger$1.call(Trig
ger.java:225)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger$1.call(Trig
ger.java:221)
[21:08:11 WARN]: at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[21:08:11 WARN]: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolEx
ecutor.java:1128)
[21:08:11 WARN]: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolE
xecutor.java:628)
[21:08:11 WARN]: at java.base/java.lang.Thread.run(Thread.java:829)
[21:08:11 WARN]: Caused by: java.io.FileNotFoundException: plugins\TriggerReactor\test.txt (지정된
파일을 찾을 수 없습니다)
[21:08:11 WARN]: at java.base/java.io.FileInputStream.open0(Native Method)
[21:08:11 WARN]: at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
[21:08:11 WARN]: at java.base/java.io.FileInputStream.(FileInputStream.java:157)
[21:08:11 WARN]: at java.base/java.io.FileInputStream.(FileInputStream.java:112)
[21:08:11 WARN]: at java.base/java.io.FileReader.(FileReader.java:60)
[21:08:11 WARN]: ... 21 more
[21:08:11 WARN]: java.lang.reflect.InvocationTargetException
[21:08:11 WARN]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance
0(Native Method)
[21:08:11 WARN]: at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:62)
[21:08:11 WARN]: at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInst
ance(DelegatingConstructorAccessorImpl.java:45)
[21:08:11 WARN]: at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490
)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.tools.ReflectionUtil.constructNew(Reflec
tionUtil.java:512)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.call
Function(Interpreter.java:1179)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.inte
rpret(Interpreter.java:993)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:554)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:516)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:516)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:270)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:516)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
t(Interpreter.java:243)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.star
tWithContextAndInterrupter(Interpreter.java:186)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger.start(Trigg
er.java:270)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger$1.call(Trig
ger.java:225)
[21:08:11 WARN]: at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger$1.call(Trig
ger.java:221)
[21:08:11 WARN]: at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[21:08:11 WARN]: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolEx
ecutor.java:1128)
[21:08:11 WARN]: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolE
xecutor.java:628)
[21:08:11 WARN]: at java.base/java.lang.Thread.run(Thread.java:829)
[21:08:11 WARN]: Caused by: java.lang.NullPointerException
[21:08:11 WARN]: at java.base/java.io.Reader.(Reader.java:167)
[21:08:11 WARN]: at java.base/java.io.BufferedReader.(BufferedReader.java:101)
[21:08:11 WARN]: at java.base/java.io.BufferedReader.(BufferedReader.java:116)
[21:08:11 WARN]: ... 21 more

commented

Could you show me the full error log with debug mode on?

commented

It is better to use a code-block for readability.

java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at io.github.wysohn.triggerreactor.tools.ReflectionUtil.constructNew(ReflectionUtil.java:512)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.callFunction(Interpreter.java:1179)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:993)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:554)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:516)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:516)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:270)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:516)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:243)
    at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.startWithContextAndInterrupter(Interpreter.java:186)
    at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger.start(Trigger.java:270)
    at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger$1.call(Trigger.java:225)
    at io.github.wysohn.triggerreactor.core.manager.trigger.Trigger$1.call(Trigger.java:221)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.io.FileNotFoundException: plugins\TriggerReactor\test.txt (지정된파일을 찾을 수 없습니다)
    at java.base/java.io.FileInputStream.open0(Native Method)
    at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
    at java.base/java.io.FileInputStream.(FileInputStream.java:157)
    at java.base/java.io.FileInputStream.(FileInputStream.java:112)
    at java.base/java.io.FileReader.(FileReader.java:60)
    ... 21 more
commented

@wysohn

io.github.wysohn.triggerreactor.tools.ReflectionUtil#constructNew

public static Object constructNew(Class<?> clazz, Object... args) throws NoSuchMethodException, InstantiationException, IllegalArgumentException, IllegalAccessException {
        if (args.length < 1) {
            return clazz.newInstance();
        } else {
            List<Constructor<?>> validConstructors = getValidExecutables(clazz, null, args, > Class::getConstructors);

            if (validConstructors.isEmpty())
                throw new NoSuchMethodException(buildFailMessage(clazz, "<init>", args));

            Constructor<?> target = findBestFit(clazz, null, validConstructors, args, (c, name, params) ->
                    c.getConstructor(params));
            if (target == null)
                throw new NoSuchMethodException(buildFailMessage(clazz, "<init>", args));

            if (target.isVarArgs()) {
                args = mergeVarargs(args, target.getParameterTypes());
            }

            try {
                return target.newInstance(args);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }

            return null;
        }
    }

Does InvocationTargetException have to be printStackTrace?
Due to this, we cannot catch a error in CATCH statement.
So I want to put this error in the method throws list like any other error.
If we can't, is there a better way?

commented

@wysohn

io.github.wysohn.triggerreactor.tools.ReflectionUtil#constructNew

public static Object constructNew(Class<?> clazz, Object... args) throws NoSuchMethodException, InstantiationException, IllegalArgumentException, IllegalAccessException {
        if (args.length < 1) {
            return clazz.newInstance();
        } else {
            List<Constructor<?>> validConstructors = getValidExecutables(clazz, null, args, > Class::getConstructors);

            if (validConstructors.isEmpty())
                throw new NoSuchMethodException(buildFailMessage(clazz, "<init>", args));

            Constructor<?> target = findBestFit(clazz, null, validConstructors, args, (c, name, params) ->
                    c.getConstructor(params));
            if (target == null)
                throw new NoSuchMethodException(buildFailMessage(clazz, "<init>", args));

            if (target.isVarArgs()) {
                args = mergeVarargs(args, target.getParameterTypes());
            }

            try {
                return target.newInstance(args);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }

            return null;
        }
    }

Does InvocationTargetException have to be printStackTrace? Due to this, we cannot catch a error in CATCH statement. So I want to put this error in the method throws list like any other error. If we can't, is there a better way?

No, feel free to change it

Should be better off catching that in the callers

commented

Fixed in #467 .