question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event without arguments outputs Exception (compilation error)

See original GitHub issue

WHen 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:closed
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
csmullercommented, Jan 25, 2021

😃 Good, then we’ll go with trigger() 👍

1reaction
csmullercommented, Jan 22, 2021

😲 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 the notify(...) methods to prevent this misunderstanding.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found