cedar-policy / cedar-java

Java bindings for the Cedar language
https://www.cedarpolicy.com
Apache License 2.0
42 stars 19 forks source link

Java integration test fails when executed against a release build of the FFI library #79

Closed ygrignon-sfdc closed 8 months ago

ygrignon-sfdc commented 9 months ago

Before opening, please confirm:

Bug Category

Other

Describe the bug

If I build CedarJavaFFI using cargo build then running CedarJava/gradlew test completes successfully. If I build CedarJavaFFI using cargo build -r then running CedarJava/gradlew test errors out with a single test failure:

Expected behavior

Running tests should succeed with both debug and release builds of CedarJavaFFI

Reproduction steps

  1. cd CedarJavaFFI
  2. cargo build
  3. cd ../CedarJava
  4. make sure your Java version is openjdk 17
  5. make sure build.gradle's environment 'CEDAR_JAVA_FFI_LIB' entry points to your debug build created by step 2
  6. ./gradlew clean test
  7. observe that the tests completed successfully
  8. cd ../CedarJavaFFI
  9. cargo build -r
  10. cd ../CedarJava
  11. update build.gradle's environment 'CEDAR_JAVA_FFI_LIB' entry to point to the release build created by step 9
  12. ./gradlew clean test
  13. observe that the tests failed

Code Snippet

N/A

Log output

$ ./gradlew clean test

> Task :compileTestJava
Note: /Users/ygrignon/projects/cedar-policy/cedar-java/CedarJava/src/test/java/com/cedarpolicy/JSONTests.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/ygrignon/projects/cedar-policy/cedar-java/CedarJava/src/test/java/com/cedarpolicy/ValidationTests.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :test

IntegrationTests > testLongExprStackOverflowDeny() FAILED
    org.opentest4j.AssertionFailedError: expected: <false> but was: <true>
        at app//org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
        at app//org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
        at app//org.junit.jupiter.api.AssertFalse.failNotFalse(AssertFalse.java:63)
        at app//org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:36)
        at app//org.junit.jupiter.api.AssertFalse.assertFalse(AssertFalse.java:31)
        at app//org.junit.jupiter.api.Assertions.assertFalse(Assertions.java:228)
        at app//com.cedarpolicy.pbt.IntegrationTests.testLongExprStackOverflowDeny(IntegrationTests.java:337)

14635 tests completed, 1 failed

> Task :test FAILED

FAILURE: Build failed with an exception.

Additional configuration

openjdk version "17.0.5" 2022-10-18 LTS OpenJDK Runtime Environment Zulu17.38+22-SA (build 17.0.5+8-LTS) OpenJDK 64-Bit Server VM Zulu17.38+22-SA (build 17.0.5+8-LTS, mixed mode, sharing)

cargo 1.74.1 (ecb9851af 2023-10-18)

Operating System

MacOS

Additional information and screenshots

No response

aaronjeline commented 9 months ago

Which version are seeing this on? Are you using one of the release branches or testing on the development branch?

ygrignon-sfdc commented 9 months ago

This is in main. Didn't try to repro on a release branch.

aaronjeline commented 9 months ago

Confirmed that release/2.4.x doesn't fail so it's not an issue w/ released code

aaronjeline commented 9 months ago

Cool, able to replicate, I'll work on solving

aaronjeline commented 9 months ago

Ah, the test that fails is one confirming behavior on stack overflow, and rust stack frames are much smaller in release mode, so I'm guessing it ends up not actually overflowing the stack.

aaronjeline commented 9 months ago

Fix here: https://github.com/cedar-policy/cedar-java/pull/80