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.

NullPointerException for ActivityButtonsImpl

See original GitHub issue
2022-06-05 16:21:28.915+0200 WARN org.javacord.core.util.gateway.PacketHandler Couldn't handle packet of type GUILD_CREATE. Please contact the developer!
 java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.databind.JsonNode.asText()" because the return value of "com.fasterxml.jackson.databind.JsonNode.get(String)" is null
	at org.javacord.core.entity.activity.ActivityButtonsImpl.<init>(ActivityButtonsImpl.java:18)
	at org.javacord.core.entity.activity.ActivityImpl.<init>(ActivityImpl.java:94)
	at org.javacord.core.entity.server.ServerImpl.<init>(ServerImpl.java:467)
	at org.javacord.core.util.handler.guild.GuildCreateHandler.handle(GuildCreateHandler.java:33)
	at org.javacord.core.util.gateway.PacketHandler.lambda$handlePacket$0(PacketHandler.java:51)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

I had to remove the packet response from Exception message as the comment is too long

According to the Discord Docs about activity button these two field can not return null, but somehow for me it throws this exception.

I have these connection parameters specified for connecting to DiscordApi:

new DiscordApiBuilder().setToken("hidden").setAllIntents()
    .setWaitForUsersOnStartup(true).setShutdownHookRegistrationEnabled(false)
    .setWaitForServersOnStartup(true).login().thenAccept(a -> {
  // My impls here
});

I created a simple diff to mark what to be changed. ActivityButtonsImpl.java

    public ActivityButtonsImpl(JsonNode data) {
-
-       this.label = data.get("label").asText();
+       this.label = data.has("label") ? data.get("label").asText() : null;
-
-       this.url = data.get("url").asText();
+       this.url = data.has("url") ? data.get("url").asText() : null;
    }

    @Override
-   public String getLabel() {
+   public Optional<String> getLabel() {
-       return label;
+       return Optional.ofNullable(label);
    }

    @Override
-   public String getUrl() {
+   public Optional<String> getUrl() {
-      return url;
+      return Optional.ofNullable(url);
    }
}

ActivityButtons.java

+ import java.util.Optional;
+
public interface ActivityButtons {
    /**
-     * Gets the text shown on the button.
+     * Gets the text shown on the button if present.
     *
-     * @return The text shown on the button.
+     * @return The text shown on the button if present.
     */
-    String getLabel();
+    Optional<String> getLabel();

    /**
-     * The url which is opened when the button is clicked.
+     * The url which is opened when the button is clicked or {@link Optional#empty()} if not present.
     *
-     * @return The url which is opened when the button is clicked.
+     * @return The url which is opened when the button is clicked or {@link Optional#empty()} if not present.
     */
-    String getUrl();
+    Optional<String> getUrl();

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KILLEliteMastecommented, Jun 5, 2022

Yeah, like I expected this only has an array with some string. Going to do a PR which addresses this issue

0reactions
montlikadanicommented, Jun 5, 2022

I thought ActivityButton implements Button, but I realized it is not the same. I copied a new exception that contains a user activity, I think this user listening to Youtube Music (or changed now): https://pastebin.com/PvMdaNbU This contains a buttons property.

Edit: I still don’t have any ActivityButton implemented in my code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException for instantiated button in action listener
The following code is a snippet of a program I am getting a nullpointer exception from. When I press the "Add" button on...
Read more >
Investigating a NullPointerException (How To) - Treehouse
We have an error! It's a common one: we have encountered an uncaught NullPointerException. Let's see how to investigate and fix it.
Read more >
What is a NullPointerException, and how do I fix it? - YouTube
... and how do I fix it?# NullPointerException exception occurred when you are trying to get something from null referenced object...
Read more >
a Java.lang.NullPointerException accurance when Clicking on ...
Hi, I'm having a weird exception while modeling on Capella 1.20. Indeed, I get a wizard with a java.lang.NullPOinterException error message ...
Read more >
Javacord - bytemeta
NullPointerException for ActivityButtonsImpl · Forum channels in a server breaks `ServerImpl#getChannels()` · Add missing fields to the Activity object.
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