This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

NullPointerException in allocChildClasses


A bug report follows:

When using a local method inside a lambda expression, a
NullPointerException is generated.  I don't know if this is even valid
code, but it shouldn't throw the exception:

    (define-simple-class <MyClass> ()
      (var)
      ((get-var) var)

      ((my-method) 
       (lambda (x) (+ x (get-var)))))

The stack trace is below.  

A simple work around is to make up the closure more explicitly:

    (define-simple-class <MyClass> ()
      (var)
      ((get-var) var)

      ((my-method) 
       (let ((self (this)))
         (lambda (x) (+ x (invoke (as <MyClass> self) 'get-var))))))

Regards,
Chris Dean

java.lang.NullPointerException
        at gnu.expr.LambdaExp.allocChildClasses(LambdaExp.java:949)
        at gnu.expr.ClassExp.compile(ClassExp.java:372)
        at gnu.expr.ClassInitializer.<init>(ClassInitializer.java:16)
        at gnu.expr.ClassExp.compileSetField(ClassExp.java:529)
        at gnu.expr.SetExp.compile(SetExp.java:151)
        at gnu.expr.Expression.compileNotePosition(Expression.java:98)
        at gnu.expr.Expression.compileWithPosition(Expression.java:69)
        at gnu.kawa.functions.AppendValues.compile(AppendValues.java:49)
        at gnu.expr.ApplyExp.compile(ApplyExp.java:161)
        at gnu.expr.ApplyExp.compile(ApplyExp.java:111)
        at gnu.expr.Expression.compileWithPosition(Expression.java:87)
        at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1376)
        at gnu.expr.Compilation.addClass(Compilation.java:1658)
        at gnu.expr.Compilation.compile(Compilation.java:908)
        at gnu.expr.Compilation.compileToFiles(Compilation.java:955)
        at kawa.lang.CompileFile.compile_to_files(CompileFile.java:92)
        at kawa.repl.processArgs(repl.java:389)
        at kawa.repl.main(repl.java:634)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]