Event without arguments outputs Exception (compilation error)
See original GitHub issueWHen I try to compile this contract:
package io.neow3j.examples.contractdev.contracts;
import io.neow3j.devpack.annotations.DisplayName;
import io.neow3j.devpack.annotations.ManifestExtra;
import io.neow3j.devpack.events.Event;
@ManifestExtra(key = "name", value = "SingleArgumentContract")
@ManifestExtra(key = "author", value = "AxLabs")
public class SingleArgumentContract {
@DisplayName("onEvent")
static Event onEvent;
public static boolean anything() throws Exception {
onEvent.notify();
return true;
}
}
The output is:
Exception in thread "main" java.lang.IndexOutOfBoundsException
at org.objectweb.asm.tree.InsnList.get(InsnList.java:94)
at io.neow3j.compiler.NeoMethod.convert(NeoMethod.java:474)
at io.neow3j.compiler.converters.MethodsConverter.handleUncachedMethodCall(MethodsConverter.java:183)
at io.neow3j.compiler.converters.MethodsConverter.handleMethodCall(MethodsConverter.java:157)
at io.neow3j.compiler.converters.MethodsConverter.handleInvoke(MethodsConverter.java:138)
at io.neow3j.compiler.converters.MethodsConverter.convert(MethodsConverter.java:73)
at io.neow3j.compiler.Compiler.handleInsn(Compiler.java:388)
at io.neow3j.compiler.NeoMethod.convert(NeoMethod.java:476)
at io.neow3j.compiler.Compiler.compileClass(Compiler.java:242)
at io.neow3j.compiler.Compiler.compileClass(Compiler.java:214)
at io.neow3j.examples.contractdev.CompileAndDeploy.main(CompileAndDeploy.java:41)
It seems that the problem is the Event
.
So… if I change to Event2Args
it works:
package io.neow3j.examples.contractdev.contracts;
import io.neow3j.devpack.annotations.DisplayName;
import io.neow3j.devpack.annotations.ManifestExtra;
import io.neow3j.devpack.events.Event;
@ManifestExtra(key = "name", value = "SingleArgumentContract")
@ManifestExtra(key = "author", value = "AxLabs")
public class SingleArgumentContract {
@DisplayName("onEvent")
static Event2Args<String, String> onEvent;
public static boolean anything() throws Exception {
onEvent.notify("test", "test");
return true;
}
}
But, if I try to compile the following (only using onEvent.notify()
in a Event2Args
type), it miserably fails:
package io.neow3j.examples.contractdev.contracts;
import io.neow3j.devpack.annotations.DisplayName;
import io.neow3j.devpack.annotations.ManifestExtra;
import io.neow3j.devpack.events.Event;
@ManifestExtra(key = "name", value = "SingleArgumentContract")
@ManifestExtra(key = "author", value = "AxLabs")
public class SingleArgumentContract {
@DisplayName("onEvent")
static Event2Args<String, String> onEvent;
public static boolean anything() throws Exception {
onEvent.notify();
return true;
}
}
In my opinion, the compiler should either not support the “Event” without parameters, or provide a better error message, or provide a way that the developer can use Event
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Registering event, why the code can compile without error?
when using a lambda expression the input parameters are inferred by the compiler. n.OnSomeEvent += (sender, e) => { };.
Read more >Publish( ) event method - Progress Software
The parameters you pass must match the parameters defined in the corresponding DEFINE EVENT statement with respect to number, data type, and mode,...
Read more >Everything you wanted to know about exceptions - PowerShell
An Exception is like an event that is created when normal error handling can't deal with the issue. Trying to divide a number...
Read more >Exceptions and Error Handling, C++ FAQ - Standard C++
First of all there are things that just can't be done right without exceptions. Consider an error detected in a constructor; how do...
Read more >Java Exceptions And Exception Handling With Examples
Exception is an event which occurrs while the program is running and it ... more meaningful output instead of the compilation errors.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
😃 Good, then we’ll go with
trigger()
👍😲 it’s the
Object.notify()
method you used there. I only see that name collision now 😒 That method is not intended to be used on events (or on anything in the devpack). But it looks like we need to find a different naming for thenotify(...)
methods to prevent this misunderstanding.