NPE in DuplicateKeyException constructor

Issue #426 resolved
Marc O'Morain created an issue

We've hit a NPE in when constructing a DuplicateKeyException

The call stack is:

File DuplicateKeyException.java line 24 in org.yaml.snakeyaml.constructor.DuplicateKeyException.<init>
File SafeConstructor.java line 100 in org.yaml.snakeyaml.constructor.SafeConstructor.processDuplicateKeys
File SafeConstructor.java line 70 in org.yaml.snakeyaml.constructor.SafeConstructor.flattenMapping
File SafeConstructor.java line 183 in org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep
File BaseConstructor.java line 434 in org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping
File SafeConstructor.java line 521 in org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct
File BaseConstructor.java line 204 in org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck
File BaseConstructor.java line 193 in org.yaml.snakeyaml.constructor.BaseConstructor.constructObject
File BaseConstructor.java line 159 in org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument
File BaseConstructor.java line 146 in org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData
File Yaml.java line 524 in org.yaml.snakeyaml.Yaml.loadFromReader
File Yaml.java line 437 in org.yaml.snakeyaml.Yaml.load

Using org.yaml/snakeyaml 1.23.

I've not tried to debug the issue yet - step 1 I wanted to log the bug.

Our internal URL to track this at CircleCI is https://rollbar.com/circle/orb-service/items/116/ (logging this for our own reference).

I'll try to get the offending YAML document, I don't have it available at present.

Comments (7)

  1. Marc O'Morain reporter

    Here is an example that fails:

    ~: foo
    ~: bar
    

    This throws:

    Error: NullPointerException   org.yaml.snakeyaml.constructor.DuplicateKeyException.<init> (DuplicateKeyException.java:24)
    
  2. Marc O'Morain reporter

    Thanks Andrey.

    This should fix it:

    public class DuplicateKeyException extends ConstructorException {
    
        protected DuplicateKeyException(Mark contextMark, Object key,
                                        Mark problemMark) {
            super("while constructing a mapping", contextMark, "found duplicate key " + String.valueOf(key), problemMark);
        }
    }
    
  3. Marc O'Morain reporter

    My Yaml is being parsed using the following loader (from Clojure):

    (defn strict-loader-options ^LoaderOptions []
      (doto (LoaderOptions.)
        (.setAllowDuplicateKeys false)))
    
    (defn strict-loader ^Yaml []
      (Yaml. (SafeConstructor.)
             (Representer.)
             (DumperOptions.)
             (strict-loader-options)))
    
  4. Marc O'Morain reporter

    Thank you Andrey (and thank you for all the time that you spend on this library).

    Will you be able to publish the new version soon? I see that you try to release twice a year – and the next release is due in February). Will you be able to publish a new jar before then?

    Marc

  5. Log in to comment