Hey, I'm new here. I'm having problems trying to u...
# announcements
d
Hey, I'm new here. I'm having problems trying to use Kotlin Jsr223, it just throws an NPE on the .eval function call... any ideas? Also is this the right place to ask?
v
Maybe better suited in #C0BT46EL8
Also, you should provide what you tried and most importantly the full stack trace
d
Well sure, but the full stacktrace just points at a random method in the library code. One second.
Copy code
<https://hastebin.de/akozacezuj.less>

Here is the whole stacktrace.
Also forgot that it works on my local windows machine... but it's my hosting where it breaks. I am using docker, and it's running on the image
openjdk:11.0.9
, but I tried a few other JDK 11 ones.
v
Doesn't look to me like an NPE in the Kotlin code, but in your script. The stacktrace shows a
ScriptException
with message
java.lang.NullPointerException
. It is thrown at https://github.com/JetBrains/kotlin/blob/v1.4.21/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/repl/KotlinJsr223JvmScriptEngineBase.kt So I guess you have some NPE in your script. Maybe you can debug it and break when it happens to see where or to get a stack trace.
d
It happens whatever script I run, and as I said it works on my local PC. The code isn't nullable either.
v
Yeah, well, as I said you still need to attach a debugger. That stack trace will not help to resolve the issue, no matter whether it is in your code or in Kotlin code, as it does not show the source of the NPE.
d
I'll see what I can do.
How do I debug it if it's running in docker though? I can't reproduce it locally... @Vampire
v
With IntelliJ 2021.1 EAP 1 a cool new feature is added, run targets. There you can setup run targets like a remote machine via SSH or a docker image and so on and you can start and debug just if it were local. If you don't want to give the EAP a chance, you could still start your bot with debug settings and then connect your IDE to it, as long as you for example have SSH access. You can then open a tunnel to the debug port and connect the IDE to that.
d
I talked to the guy I'm doing the hosting with, it doesn't seem like the easiest thing to setup. These "I work here but not there" issues are really annoying.
v
Well, if it runs on docker, did you try to run it on docker locally and see whether it reproduces?
And you are not having SSH access to the machine where it is hosted, do you?
d
I won't set up a WSL just to run one thing, since I'm using Windows, and I do have SSH access to my container.
I can maybe try it on my Linux laptop.
v
If you have SSH access to your container, why do you need your hosting guy?
Just connect per SSH to your container with a port-forwarding that forwards to the debugger port you configured
I did that myself multiple times already, works like a charm
And with the new feature in IntelliJ 2021.1 it will be a breeze
d
Can you provide a website explaining this or something?
v
What exactly?
Are you using IntelliJ?
You are basically building a bridge via SSH. If you for example start your bot with
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
And do an SSH connection using
ssh -L 1234:localhost:5005 yourHost
Then you can use a "Remote JVM Debug" run configuration in IntelliJ that connects to localhost port
1234
. It will then connect to the local port
1234
. On this port your SSH client listens and forwards on the remote end to
localhost:5005
where your bot is waiting for a debugger. You can also do
ssh -L 5005:localhost:5005 yourHost
the different ports were just to better explain.
d
Aham
I'll try it thanks.
It turns out, the Kotlin engine doesn't like null bindings unlike other ones... With knowing that, it was an easy fix.
👌 1