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.

Can't use newer java.util.Map implementation with JavalinVue::stateFunction

See original GitHub issue

I get this weird error as if I’m trying to set a null key:

JavalinVue.stateFunction = ctx -> Map.of(
    "currentMsisdn", ctx.sessionAttribute("currentMsisdn"), 
    "verifiedMsisdn", ctx.sessionAttribute("verifiedMsisdn")
);
java.lang.NullPointerException
        at java.base/java.util.Objects.requireNonNull(Objects.java:222)
        at java.base/java.util.ImmutableCollections$MapN.<init>(ImmutableCollections.java:964)
        at java.base/java.util.Map.of(Map.java:1328)
        ...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fwgreencommented, Nov 17, 2019

I’m guessing Map.of doesn’t accept null-values?

Ah! I see, and Context::sessionAttribute returns a nullable. Hopefully the Kotlin team will add a @JvmOptional annotation to their list of interop tools 😄. I’m closing the issue as the error is easily avoided by using the old Map, but maybe you can document the behavior so others can avoid this problem.

Thanks again for your quick reply.

0reactions
tipsycommented, Nov 18, 2019

I’ll add the info label then 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot implement java.util.Map - kotlin - Stack Overflow
I can't fully explain it, but it seems Kotlin really doesn't like referencing Java collections directly. For example, this is considered a ...
Read more >
Map (Java Platform SE 8 ) - Oracle Help Center
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This...
Read more >
How to use a Map in Java - Code by Amir | Amir Boroumand
Let's create a HashMap with Integer keys and String values: Map<Integer, String> map = new HashMap<> ...
Read more >
Immutable Map Implementations in Java | Baeldung
util.Map using ImmutableMap. It throws an UnsupportedOperationException whenever we try to modify it. Since it contains its own private data, ...
Read more >
How to use keySet method in java.util.Map - CodeGym
The feature of this Set collection, that keeps the keys, is that there cannot be duplicate elements in it. The set is backed...
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