help-jel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-jel] Null return from String method


From: Mark Taylor
Subject: [Help-jel] Null return from String method
Date: Tue, 18 Jun 2019 15:25:52 +0000

Dear Konstantin,

there seems to be something surprising going on if I return null
from a String-typed method during JEL evaluation.  Here is a test
program:

    import gnu.jel.CompiledExpression;
    import gnu.jel.Evaluator;
    import gnu.jel.Library;

    public class STest {
        public static void main( String[] args ) throws Throwable {
            Library lib = new Library( new Class[] { STest.ALib.class },
                                       null, null, null, null );
            for ( int i = 0; i < 4; i++ ) {
                String sexpr = "txt(" + i + ")";
                CompiledExpression compex = Evaluator.compile( sexpr, lib );
                System.out.println( sexpr + "=" + compex.evaluate( null ) );
            }
        }

        public static class ALib {
            public static String txt( int i ) {
                return i == 2 ? null : Integer.toString(i);
            }
        }
    }

If I run it with jel_g.jar from http://ftp.gnu.org/gnu/jel/jel-2.1.1.tar.gz
I see this on stdout/stderr:

    txt(0)=0
    txt(1)=1
    [DEBUG] typeIDObject(what)=8
    [DEBUG] instead.resID=11
    [DEBUG] what=null
    txt(2)=null
    txt(3)=3

If I run it with jel.jar, I see this:

    txt(0)=0
    txt(1)=1
    Exception in thread "main" java.lang.NullPointerException
            at java.io.DataOutputStream.writeUTF(DataOutputStream.java:347)
            at java.io.DataOutputStream.writeUTF(DataOutputStream.java:323)
            at gnu.jel.ClassFile.getUTFIndex(Unknown Source)
            at gnu.jel.ClassFile.getIndex(Unknown Source)
            at gnu.jel.ClassFile.codeLDC(Unknown Source)
            at gnu.jel.OPload.compile(Unknown Source)
            at gnu.jel.OPunary.compile(Unknown Source)
            at gnu.jel.Evaluator.getImage(Unknown Source)
            at gnu.jel.Evaluator.compileBits(Unknown Source)
            at gnu.jel.Evaluator.compile(Unknown Source)
            at gnu.jel.Evaluator.compile(Unknown Source)
            at STest.main(STest.java:12)

This doesn't seem to be a new problem at JEL 2.1.1, all the versions
I have lying around seem to do the same thing.  Given which, I am
extremely surprised that I haven't come across this before in
more than 15 years of heavy JEL use, but I suppose most of my
functions are numeric and not strings.

Can you comment?

Many thanks,

Mark

--
Mark Taylor   Astronomical Programmer   Physics, Bristol University, UK
address@hidden +44-117-9288776  http://www.star.bris.ac.uk/~mbt/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]