Issue2232

classification
Title: java.lang.NullPointerException in org.python.compiler.CodeCompiler.visitLambda
Type: Severity: normal
Components: Versions: Jython 2.7
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: zyasoft Nosy List: Arfrever, offby1, zyasoft
Priority: high Keywords:

Created on 2014-11-20.23:41:07 by Arfrever, last changed 2015-01-13.23:00:59 by zyasoft.

Messages
msg9214 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2014-11-20.23:41:06
java.lang.NullPointerException is raised when trying to load test suite of characteristic.
https://pypi.python.org/pypi/characteristic/14.2.0

$ jython2.7 -c 'import test_characteristic'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
java.lang.NullPointerException
        at org.python.compiler.CodeCompiler.visitLambda(CodeCompiler.java:2324)
        at org.python.antlr.ast.Lambda.accept(Lambda.java:138)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.makeArray(CodeCompiler.java:424)
        at org.python.compiler.CodeCompiler.visitCall(CodeCompiler.java:1859)
        at org.python.antlr.ast.Call.accept(Call.java:248)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.applyDecorators(CodeCompiler.java:542)
        at org.python.compiler.CodeCompiler.visitClassDef(CodeCompiler.java:2424)
        at org.python.antlr.ast.ClassDef.accept(ClassDef.java:236)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.suite(CodeCompiler.java:1473)
        at org.python.compiler.CodeCompiler.visitSuite(CodeCompiler.java:1468)
        at org.python.antlr.ast.Suite.accept(Suite.java:121)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.parse(CodeCompiler.java:317)
        at org.python.compiler.Module.codeConstant(Module.java:502)
        at org.python.compiler.Module.codeConstant(Module.java:482)
        at org.python.compiler.CodeCompiler.visitFunctionDef(CodeCompiler.java:513)
        at org.python.antlr.ast.FunctionDef.accept(FunctionDef.java:218)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.suite(CodeCompiler.java:1473)
        at org.python.compiler.CodeCompiler.visitSuite(CodeCompiler.java:1468)
        at org.python.antlr.ast.Suite.accept(Suite.java:121)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.parse(CodeCompiler.java:317)
        at org.python.compiler.Module.codeConstant(Module.java:502)
        at org.python.compiler.CodeCompiler.visitClassDef(CodeCompiler.java:2411)
        at org.python.antlr.ast.ClassDef.accept(ClassDef.java:236)
        at org.python.antlr.ast.Module.traverse(Module.java:128)
        at org.python.antlr.Visitor.traverse(Visitor.java:12)
        at org.python.compiler.CodeCompiler.visitModule(CodeCompiler.java:367)
        at org.python.antlr.ast.Module.accept(Module.java:121)
        at org.python.antlr.Visitor.visit(Visitor.java:26)
        at org.python.compiler.CodeCompiler.parse(CodeCompiler.java:317)
        at org.python.compiler.Module.codeConstant(Module.java:502)
        at org.python.compiler.Module.codeConstant(Module.java:482)
        at org.python.compiler.Module.compile(Module.java:656)
        at org.python.core.imp.compileSource(imp.java:330)
        at org.python.core.imp.createFromSource(imp.java:348)
        at org.python.core.imp.loadFromSource(imp.java:580)
        at org.python.core.imp.find_module(imp.java:480)
        at org.python.core.imp.import_next(imp.java:737)
        at org.python.core.imp.import_module_level(imp.java:856)
        at org.python.core.imp.importName(imp.java:946)
        at org.python.core.ImportFunction.__call__(__builtin__.java:1304)
        at org.python.core.PyObject.__call__(PyObject.java:395)
        at org.python.core.__builtin__.__import__(__builtin__.java:1257)
        at org.python.core.imp.importOne(imp.java:965)
        at org.python.pycode._pyx1.f$0(<string>:1)
        at org.python.pycode._pyx1.call_function(<string>)
        at org.python.core.PyTableCode.call(PyTableCode.java:166)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1327)
        at org.python.core.Py.exec(Py.java:1371)
        at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:222)
        at org.python.util.jython.run(jython.java:366)
        at org.python.util.jython.main(jython.java:145)

java.lang.NullPointerException: java.lang.NullPointerException

Exception is caused by this code:

    def test_store_attributes(self):
        """
        store_attributes is called on the class to store the attributes that
        were passed in.
        """
        attrs = [Attribute("a"), Attribute("b")]

        @attributes(
            attrs, store_attributes=lambda cls, a: setattr(cls, "foo", a)
        )
        class C(object):
            pass

        assert C.foo == attrs
msg9310 (view) Author: Jim Baker (zyasoft) Date: 2015-01-06.04:09:54
Looks like the AST is being visited as expected until the NPE. In any event, characteristic looks like a really good test suite for Jython's support of class decorators. Fun!
msg9321 (view) Author: Jim Baker (zyasoft) Date: 2015-01-06.22:53:14
Fixed as of https://hg.python.org/jython/rev/56b94dc065ff

Now works with the latest version of characteristic, https://pypi.python.org/pypi/characteristic/14.3.0

$ ~/jythondev/jython27/dist/bin/py.test-jython
============================= test session starts ==============================
platform java1.7.0_21 -- Python 2.7.0 -- py-1.4.26 -- pytest-2.6.4
collected 87 items

test_characteristic.py .......................................................................................

========================== 87 passed in 1.81 seconds ===========================
History
Date User Action Args
2015-01-13 23:00:59zyasoftsetstatus: pending -> closed
2015-01-06 22:53:14zyasoftsetstatus: open -> pending
resolution: fixed
messages: + msg9321
2015-01-06 04:09:55zyasoftsetpriority: high
assignee: zyasoft
messages: + msg9310
2015-01-05 21:13:58offby1setnosy: + offby1
2014-12-15 18:37:38zyasoftsetnosy: + zyasoft
2014-11-20 23:41:07Arfrevercreate