Restore the `Boolean` constructors for binary compatibility of dependent projects?

Issue #412 resolved
ahbittin created an issue

This recent commit

https://bitbucket.org/asomov/snakeyaml/commits/6cb855839ebc1f3796cff26aa6e5423f1395b975

changed the API in some places to take a DumperOptions.FlowStyle flowStyle instead of a Boolean. This has caused some downstream projects which used the old API to break if bundled with a more recent version of snakeyaml.

Would you consider accepting a PR that restores the old constructors, marked deprecated, and simply forwarding to the new constructors, and cutting a new version so that we could use an even newer version eg 1.22 and not lose hair & sleep over these delicate version alignments.

See for example:

https://github.com/FasterXML/jackson-dataformats-text/issues/81

(It would be fair for those projects to more accurately mark which versions of snakeyaml they are compatible with, e.g. as [1.18,1.20) but there are a few others I've encountered as well, e.g. jclouds-byon, so I for one would be grateful if snake could offer this compatibility for a while yet!)

Happy to help contribute this.

Comments (10)

  1. ahbittin reporter

    I get the same errors on the revision immediately before my commits, and the problem doesn't seem related to my changes.

    FWIW it looks like the problem is something attempting to access the private constructor java.util.Optional(java.lang.Object).

    For the record, the errors are:

    Tests in error: 
      Java8OptionalTest.testJava8OptionalDumpLoad:35->OptionalTesting.dumpLoadOptional:152 » Constructor
      Java8OptionalTest.testJava8OptionalStringLoad:30->OptionalTesting.loadOptionalString:136 » Constructor
    

    With detailed cause:

    testJava8OptionalDumpLoad(org.yaml.snakeyaml.issues.issue310.Java8OptionalTest)  Time elapsed: 0.007 sec  <<< ERROR!
    org.yaml.snakeyaml.constructor.ConstructorException: 
    Cannot create property=salary for JavaBean=Person{name='Neo Anderson', salary=Optional.empty}
     in 'string', line 1, column 1:
        !!org.yaml.snakeyaml.issues.issu ... 
        ^
    Cannot create property=income for JavaBean=Salary{income=Optional.empty}
     in 'string', line 3, column 10:
        salary: [!!org.yaml.snakeyaml.issues.issu ... 
                 ^
    java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Optional(java.lang.Object) accessible: module java.base does not "opens java.util" to unnamed module @46897293
     in 'string', line 3, column 79:
         ... OptionalTesting$Salary {income: [123456.78]}]
                                             ^
    
     in 'string', line 3, column 9:
        salary: [!!org.yaml.snakeyaml.issues.iss ... 
                ^
    
        at org.yaml.snakeyaml.issues.issue310.Java8OptionalTest.testJava8OptionalDumpLoad(Java8OptionalTest.java:35)
    Caused by: org.yaml.snakeyaml.constructor.ConstructorException: 
    Cannot create property=income for JavaBean=Salary{income=Optional.empty}
     in 'string', line 3, column 10:
        salary: [!!org.yaml.snakeyaml.issues.issu ... 
                 ^
    java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Optional(java.lang.Object) accessible: module java.base does not "opens java.util" to unnamed module @46897293
     in 'string', line 3, column 79:
         ... OptionalTesting$Salary {income: [123456.78]}]
                                             ^
    
        at org.yaml.snakeyaml.issues.issue310.Java8OptionalTest.testJava8OptionalDumpLoad(Java8OptionalTest.java:35)
    Caused by: org.yaml.snakeyaml.error.YAMLException: java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Optional(java.lang.Object) accessible: module java.base does not "opens java.util" to unnamed module @46897293
        at org.yaml.snakeyaml.issues.issue310.Java8OptionalTest.testJava8OptionalDumpLoad(Java8OptionalTest.java:35)
    Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make private java.util.Optional(java.lang.Object) accessible: module java.base does not "opens java.util" to unnamed module @46897293
        at org.yaml.snakeyaml.issues.issue310.Java8OptionalTest.testJava8OptionalDumpLoad(Java8OptionalTest.java:35)
    
  2. ahbittin reporter

    Changing <jdk9-illegal-access-level>deny</jdk9-illegal-access-level> to <jdk9-illegal-access-level>permit</jdk9-illegal-access-level> in the pom.xml seems to solve the problem. It looks like deny was set explicitly (overriding the jdk9 default of permit) in revision 1121. With deny I believe the failure is the correct behaviour.

    This SO question has useful background: https://stackoverflow.com/questions/46230413/jdk9-an-illegal-reflective-access-operation-has-occurred-org-python-core-pysys/46230678

  3. Andrey Somov

    For your information: I have changed the Javadoc comment to normal comments to avoid build errors. If you want the proper Javadoc comments then you can submit another pull request (please check that Maven does not complain)

    In the meantime you can test the latest SNAPSHOT from Sonatype

  4. Log in to comment