Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2612 NPE when trying to import classes #86

Closed
wants to merge 1 commit into from

Conversation

jamesmudd
Copy link
Member

No description provided.

@Stewori
Copy link
Contributor

Stewori commented Aug 6, 2017

This looks good to me. It is a simple change and I think we can safely accept it....

@jamesmudd
Copy link
Member Author

Although this does resolve the issue I think @jeff5 may be able to propose a better fix. Discussion on http://bugs.jython.org/issue2612

darjus pushed a commit that referenced this pull request Aug 27, 2017
This was a regresion caused when trying to deal with non-ascii paths in
the preparation of a log message. Thanks to James Mudd for diagnosing
this. Also #86.
@jeff5
Copy link
Member

jeff5 commented Aug 27, 2017

Looking at what this message would have been about (formatting of which produces the NPE), the foolproof choice is to get the string from the directory object itself. Fixed at https://hg.python.org/jython/rev/39b0bd0dcd01, I claim.

Just for now, I'm resisting the temptation to rationalise the surrounding code. :)

@jeff5 jeff5 closed this Aug 27, 2017
@jamesmudd jamesmudd deleted the 2612 branch September 26, 2017 15:29
@tokunbo
Copy link

tokunbo commented Dec 11, 2018

Did this issue return? My compiled class comes from scala source, instead of java-source in case that somehow matters.

├── testutils
│   ├── JMHTTPClient.class
│   └── JMHTTPClient.scala
└── worker.py

pikachu@POKEMONGYM ~/Forwardz/jmnarau $ java -jar ../usefuljars/jython-standalone-2.7.1.jar 
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_181
Type "help", "copyright", "credits" or "license" for more information.
>>> import testutils
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
java.lang.NullPointerException
        at org.python.core.PyString.encode_UnicodeEscape(PyString.java:339)
        at org.python.core.imp.loadFromSource(imp.java:627)
        at org.python.core.imp.find_module(imp.java:551)
        at org.python.core.imp.import_next(imp.java:838)
        at org.python.core.imp.import_module_level(imp.java:957)
        at org.python.core.imp.importName(imp.java:1057)
        at org.python.core.ImportFunction.__call__(__builtin__.java:1280)
        at org.python.core.PyObject.__call__(PyObject.java:450)
        at org.python.core.__builtin__.__import__(__builtin__.java:1232)
        at org.python.core.imp.importOne(imp.java:1076)
        at org.python.pycode._pyx1.f$0(<stdin>:1)
        at org.python.pycode._pyx1.call_function(<stdin>)
        at org.python.core.PyTableCode.call(PyTableCode.java:171)
        at org.python.core.PyCode.call(PyCode.java:18)
        at org.python.core.Py.runCode(Py.java:1614)
        at org.python.core.Py.exec(Py.java:1658)
        at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
        at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:131)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:116)
        at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:62)
        at org.python.util.InteractiveConsole.push(InteractiveConsole.java:187)
        at org.python.util.InteractiveConsole._interact(InteractiveConsole.java:168)
        at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:126)
        at org.python.util.jython.run(jython.java:419)
        at org.python.util.jython.main(jython.java:142)
java.lang.NullPointerException: java.lang.NullPointerException
>>> pikachu@POKEMONGYM ~/Forwardz/jmnarau $  sha1sum ../usefuljars/jython-standalone-2.7.1.jar 
942c3294840dc9dfb3528d775f4d02a6d57c421f  ../usefuljars/jython-standalone-2.7.1.jar
pikachu@POKEMONGYM ~/Forwardz/jmnarau $ 

@jeff5
Copy link
Member

jeff5 commented Dec 11, 2018

Not returned, just not fixed in 2.7.1 which you are clearly using.

Despite the best intentions, we have not released a 2.7.2 yet. You could wait or build your own snapshot JAR.

@tokunbo
Copy link

tokunbo commented Dec 11, 2018

@jeff5 Ah, okay. Thanks. I can wait -^_^-
A suitable workaround I found, was to package the class in a jar then put the jar on the classpath.

pikachu@POKEMONGYM ~/Forwardz/jmnarau $ ~/Forwardz/jdk1.8.0_191/bin/jar cvf ./JMHTTPClient.jar testutils/JMHTTPClient.class
added manifest
adding: testutils/JMHTTPClient.class(in = 7055) (out= 3391)(deflated 51%)

Then, move away from that directory such that relative-dir testutils/JMHTTPClient.class does not exist. (or rename it or something, so only the jar can resolve testutils/JMHTTPClient)

pikachu@POKEMONGYM ~/Forwardz/jmnarau $ cd ..

Then.....

pikachu@POKEMONGYM ~/Forwardz $  java -cp ./jmnarau/JMHTTPClient.jar:./usefuljars/jython-standalone-2.7.1.jar:$( find /home/pikachu/Forwardz/scala-2.12.7 /home/pikachu/Forwardz/apache-jmeter-5.0 -name '*jar' | tr "\n" ":" ) org.python.util.jython
Jython 2.7.1 (default:0df7adb1b397, Jun 30 2017, 19:02:43) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_181
Type "help", "copyright", "credits" or "license" for more information.
>>> from testutils import JMHTTPClient
>>>

⚠️ It's important that the Java/Scala class is defined as being in a package of the same name as the folder-structure it was in when the jar command was ran. The Scala class above has the following as the first line: package testutils because the class is inside a folder named "testutils" within the jar. If it was "testutils/misc/clients/JMHTTPClient.class", then the package has to be package testutils.misc.clients

jeff5 added a commit to jeff5/jython-nightjar that referenced this pull request May 30, 2020
This was a regresion caused when trying to deal with non-ascii paths in
the preparation of a log message. Thanks to James Mudd for diagnosing
this. Also jython/frozen-mirror#86.
jeff5 added a commit to jeff5/jython-nightjar that referenced this pull request May 30, 2020
This was a regresion caused when trying to deal with non-ascii paths in
the preparation of a log message. Thanks to James Mudd for diagnosing
this. Also jython/frozen-mirror#86.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants