youxinren / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

java.lang.NoClassDefFoundError: org/yaml/snakeyaml/parser/ParserImpl$ParseFlowMappingValue #71

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Dump a nested hashmap, as defined below
2. Load the nested hashmap.

The actual yaml data that produces an error, as generated by snakeyaml:
proposals:
  relet:
    hello world:
      code: print "hello world"
      support: {relet: 'no'}

Data that is loaded correctly:
proposals:
  relet:
    hello world:
      code: print "hello world"
      support: {}

What is the expected output? What do you see instead?
NoClassDefFoundError: java.lang.NoClassDefFoundError: 
org/yaml/snakeyaml/parser/ParserImpl$ParseFlowMappingValue

What version of the product are you using? On what operating system?

snakeyaml 1.6 release
called from
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54) 
[OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_18
on Ubuntu Lucid

Original issue reported on code.google.com by thomas.h...@gmail.com on 8 Jul 2010 at 1:24

GoogleCodeExporter commented 9 years ago
Data in the form

proposals:
  relet:
    hello world:
      code: print "hello world"
      support: 
        relet: no

works as well. 

Original comment by thomas.h...@gmail.com on 8 Jul 2010 at 1:37

GoogleCodeExporter commented 9 years ago
The issue disappears when removing the 'private' attribute of the class (I 
removed it on all inner classes, just to be sure).

Original comment by thomas.h...@gmail.com on 8 Jul 2010 at 2:06

GoogleCodeExporter commented 9 years ago
All the YAML documents you provided are loaded by SnakeYAML 1.6 without errors.

Can you please provide some code to see what is failing ?

I did not quite catch your message about "private attribute of the class". When 
the class is private then Java does not allow SnakeYAML to create an instance. 
But the error message is unrelated to this problem.

-
Andrey

Original comment by py4fun@gmail.com on 8 Jul 2010 at 3:00

GoogleCodeExporter commented 9 years ago
Ok, I am trying to make more sense then. :)

I am running the following code as a jython webapp for tomcat:

from javax.servlet.http import HttpServlet
from org.yaml.snakeyaml import Yaml
from java.io import FileWriter, FileInputStream
...
class myServlet (HttpServlet):
  def doPost(self, request, response):
    ...
    self.yaml = Yaml()
    self.data = self.yaml.load(FileInputStream("/var/lib/tomcat6/webapps/myapp/data/data.yaml"))
    # do something with data
    self.yaml.dump(self.data, FileWriter("/var/lib/tomcat6/webapps/myapp/data/data.yaml"))

If I create the above nested dictionary/LinkedHashMap data structure in my 
code, it is dumped in the first format. Loading this format fails with said 
exception when I next call the servlet.
If I modify the format manually in the meantime, as per the other two examples, 
the structure is read correctly, but dumped, again, in the first format. 

It may have to do with jython trying to instantiate the inner classes in the 
process of interpreting/compiling the jython code that calls Yaml.load(). I am 
not too familiar with its inner mode of operation yet.  

Original comment by thomas.h...@gmail.com on 8 Jul 2010 at 3:36

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is the jython program I used for testing:

print "Hello !"
import sys
sys.path.append('/home/snake/jython2.5.1/extlibs/snakeyaml-1.6.jar')

from org.yaml.snakeyaml import Yaml
from java.io import FileWriter, FileInputStream

yaml = Yaml()
data = yaml.load(FileInputStream("/home/snake/jython2.5.1/data.yaml"))
print data
yaml.dump(data, FileWriter("/home/snake/jython2.5.1/data.yaml"))

No problem so far.

Can you please try to identify the minimal code which fails to see the problem ?
Why private classes are involved if you use pure LinkedHashMap ?

-
Andrey

Original comment by py4fun@gmail.com on 9 Jul 2010 at 9:47

GoogleCodeExporter commented 9 years ago
Hi Andrey,

I can't seem to reproduce the bug after switching back to the unpatched 
version. So I guess I'm happy. 

Sorry to have bothered you. :)

Thomas

Original comment by thomas.h...@gmail.com on 13 Jul 2010 at 10:01

GoogleCodeExporter commented 9 years ago
(I assume you patched jython and not SnakeYAML :)
You may also try to use PyYAML. But my experience shows that using PyYAML under 
jython is many times (more then 10) slower then SnakeYAML. This is because you 
have to apply pure python code without C libraries.

Original comment by py4fun@gmail.com on 13 Jul 2010 at 12:24