NPE in PolyglotLanguageContext.toHostValue

Christian Humer christian.humer at gmail.com
Tue Jul 24 13:01:15 UTC 2018


Hi Adam,

First, welcome! Thanks for giving Truffle a go.

The NPE you are seeing comes from the fact that the CallTarget that you are
returning in SmolLanguage#parse returns itself a Java null value when
called.
A CallTarget is never expected to return null. Instead we typically use
singleton values that represent null. We have some documentation here[1]
why we do this.
So to fix this make sure your RootNodes always return a value.

That being said, the NPE is not a good error for this. We will fix that in
RC5.

Hope this helps.
Feel free to also checkout our Gitter channel for further questions:
https://gitter.im/graalvm/graal-core

Good luck!

- Christian Humer


[1]
https://github.com/graalvm/simplelanguage/blob/master/language/src/main/java/com/oracle/truffle/sl/runtime/SLNull.java#L54






On Tue, Jul 24, 2018 at 1:06 PM Adam Kövári <kovariadam at gmail.com> wrote:

> Hello,
>
> I am very interested in learning the Truffle API, I find it really amazing
> so far.
>
> I am trying to implement a simple expression language [1], based on
> SimpleLanguage project, but I got stuck and I am not really sure where the
> problem might be.
>
> Perhaps someone understands what this means?
>
> org.graalvm.polyglot.PolyglotException: java.lang.NullPointerException
>         at
> com.oracle.truffle.api.vm.PolyglotLanguageContext.toHostValue(PolyglotLanguageContext.java:585)
>         at
> com.oracle.truffle.api.vm.PolyglotContextImpl.eval(PolyglotContextImpl.java:789)
>         at org.graalvm.polyglot.Context.eval(Context.java:313)
>         at org.graalvm.polyglot.Context.eval(Context.java:338)
>         at
> smol.SmolSimpleExpressionTest.unitValueTest(SmolSimpleExpressionTest.java:74)
>>
>
> This can be easily reproduced by running:
>
> $ mvn tests
>
> My java version:
>
> $ java -version
> java version "1.8.0_172"
> Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
> GraalVM 1.0.0-rc3 (build 25.71-b01-internal-jvmci-0.45, mixed mode)
>
>
> Would someone be able to advice, any ideas or pointers are most welcome.
>
>
> Thanks,
> Adam
>
> [1] https://github.com/akovari/smol
>


More information about the graal-dev mailing list