metadatacenter / cedar-config-library

0 stars 1 forks source link

Fix failing unit tests #4

Open martinjoconnor opened 10 months ago

martinjoconnor commented 10 months ago

Some unit tests fail, e.g.,

13:41:11.767 [main] DEBUG org.eclipse.jetty.util.log - Logging to Logger[org.eclipse.jetty.util.log] via org.eclipse.jetty.util.log.Slf4jLog 13:41:11.768 [main] INFO org.eclipse.jetty.util.log - Logging initialized @418ms to org.eclipse.jetty.util.log.Slf4jLog 13:41:11.799 [main] DEBUG org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl - Adding composing constraint: ConstraintDescriptorImpl{annotation=javax.validation.constraints.NotNull, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={message={javax.validation.constraints.NotNull.message}, payload=[Ljava.lang.Class;@7728643a, groups=[Ljava.lang.Class;@320e400}, constraintType=GENERIC}. 13:41:11.799 [main] DEBUG org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl - Adding composing constraint: ConstraintDescriptorImpl{annotation=javax.validation.constraints.Size, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={groups=[Ljava.lang.Class;@28c0b664, min=1, message={javax.validation.constraints.Size.message}, payload=[Ljava.lang.Class;@2c444798, max=2147483647}, constraintType=GENERIC}. 13:41:11.799 [main] DEBUG org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl - Adding composing constraint: ConstraintDescriptorImpl{annotation=javax.validation.constraints.NotNull, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={message={javax.validation.constraints.NotNull.message}, payload=[Ljava.lang.Class;@68ed96ca, groups=[Ljava.lang.Class;@6d1310f6}, constraintType=GENERIC}. 13:41:11.800 [main] DEBUG org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl - Adding composing constraint: ConstraintDescriptorImpl{annotation=javax.validation.constraints.Size, payloads=[], hasComposingConstraints=true, isReportAsSingleInvalidConstraint=false, elementType=FIELD, definedOn=DEFINED_LOCALLY, groups=[interface javax.validation.groups.Default], attributes={groups=[Ljava.lang.Class;@3228d990, min=1, message={javax.validation.constraints.Size.message}, payload=[Ljava.lang.Class;@54e7391d, max=2147483647}, constraintType=GENERIC}. java.lang.reflect.InaccessibleObjectException: Unable to make field private static final java.util.HashMap java.lang.ProcessEnvironment.theEnvironment accessible: module java.base does not "opens java.lang" to unnamed module @60d14f0f at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)

egyedia commented 10 months ago

The problem is this block:

      Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
      Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
      theEnvironmentField.setAccessible(true);

From Java9 this contradicts the module system restrictions. One way around this would be to upgrade to JUnit5, and use one of the solutions mentioned here: http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java

Upgrading to JUnit5 might be a considerable amount of work, although there are migration tools in IntelliJ Idea that can help.