If I reference the SnakeYAML jar directly from a test program (see bottom), everything works. If I’m inside my Maven-created project, I get the following output from my unit tests:
java.lang.NoSuchMethodError: java.util.LinkedList.push(Ljava/lang/Object;)V at org.yaml.snakeyaml.scanner.ScannerImpl.addIndent(ScannerImpl.java:482) at org.yaml.snakeyaml.scanner.ScannerImpl.fetchBlockEntry(ScannerImpl.java:653) at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:268) at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:178) at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:213) at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:172) at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:163) at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:66) at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:60) at org.yaml.snakeyaml.Loader.load(Loader.java:35) at org.yaml.snakeyaml.Yaml.load(Yaml.java:134)
Since Maven couldn’t find SnakeYAML in the central repos, I manually installed it into my local repo. In case it matters, I’m on a Mac using SnakeYAML 0.9, and Maven 2.0.9.
Sample YAML File
- accountCode: foo accountId: 1 email: foo@bar.com userId: 1
Working Test Program
import java.io.*; import java.util.*; import org.yaml.snakeyaml.Yaml; /** * Testing SnakeYAML. * * @author Hank Gay */ public final class Foo { public static void main(final String[] args) throws Exception { final Yaml yaml = new Yaml(); Reader reader = null; try { reader = new FileReader('/tmp/foo.yaml'); System.out.println(yaml.load(reader)); } catch (final FileNotFoundException fnfe) { System.err.println('We had a problem reading the YAML from the file because we couldn't find the file.' + fnfe); } finally { if (null != reader) { try { reader.close(); } catch (final IOException ioe) { System.err.println('We got the following exception trying to clean up the reader: ' + ioe); } } } } }
Seems like a JDK version issue:
LinkedList#pushwas introduced in Java 6.Try setting
JAVA_HOMEto the correct version before running Maven.