[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-jel] Null return from String method
From: |
Konstantin L. Metlov |
Subject: |
Re: [Help-jel] Null return from String method |
Date: |
Tue, 18 Jun 2019 20:03:32 +0300 |
User-agent: |
SquirrelMail/1.4.23 [SVN] |
Dear Mark,
Yes, this seems to be a bug in codeLDC method of the class file. It used
to handle the null object references by coding the "aconst_null"
instruction. But since the string concatenation handling was added to JEL
(by instantiating the StringBuffer as Java does) the strings are handled
specially. The string storage branch must also check for null and code
"aconst_null" in this case.
The fix should be (untested) replacing
case 11:
short_opcodes=0;
primitiveID=8;
break;
by
case 11:
if (o==null)
short_opcodes=0x01; //| aconst_null
else
short_opcodes=0;
primitiveID=8;
break;
I'll implement and test this for the next release.
With the best regards,
Konstantin.
> 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/
>
> _______________________________________________
> Help-jel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-jel
>