Skip to content

UnsatisfiedLinkError on Windows with bundled cedar_java_ffi.dll #304

Open

Description

@drnta

Before opening, please confirm:

Bug Category

Other

Describe the bug

The attempt to execute simple Java application with cedar-java-uber dependency

<dependency>
    <groupId>com.cedarpolicy</groupId>
    <artifactId>cedar-java</artifactId>
    <classifier>uber</classifier>
    <version>4.3.0</version>
</dependency>

on Windows 10 environment fails with UnsatisfiedLinkError. Looks like the dll does not export the Java functions.

Probably the cause can be in zigbuild usage.
For the bundled dll the dumpbin shows

dumpbin /EXPORTS dlls/original/cedar_java_ffi.dll
Microsoft (R) COFF/PE Dumper Version 14.42.34436.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file dlls\original\cedar_java_ffi.dll

File Type: DLL

  Section contains the following exports for cedar_java_ffi.dll

    00000000 characteristics
           0 time date stamp
        0.00 version
           1 ordinal base
          33 number of functions
          33 number of names

    ordinal hint RVA      name

          1    0 002A58D0 _GCC_specific_handler
          2    1 008E67C0 _Unwind_Backtrace
          3    2 008FB940 _Unwind_DeleteException
          4    3 008E6750 _Unwind_FindEnclosingFunction
          5    4 008E6830 _Unwind_Find_FDE
          6    5 002A6050 _Unwind_ForcedUnwind
          7    6 008E68C0 _Unwind_GetCFA
          8    7 008E66B0 _Unwind_GetDataRelBase
          9    8 008FB960 _Unwind_GetGR
         10    9 008FB990 _Unwind_GetIP
         11    A 008E68F0 _Unwind_GetIPInfo
         12    B 002A60B0 _Unwind_GetLanguageSpecificData
         13    C 002A60C0 _Unwind_GetRegionStart
         14    D 008E6700 _Unwind_GetTextRelBase
         15    E 002A5D80 _Unwind_RaiseException
         16    F 002A5DC0 _Unwind_Resume
         17   10 008E6640 _Unwind_Resume_or_Rethrow
         18   11 008FB980 _Unwind_SetGR
         19   12 008FB9C0 _Unwind_SetIP
         20   13 00904760 unw_get_fpreg
         21   14 00904830 unw_get_proc_info
         22   15 00904880 unw_get_proc_name
         23   16 00904690 unw_get_reg
         24   17 00904AD4 unw_getcontext
         25   18 00904660 unw_init_local
         26   19 009048B0 unw_is_fpreg
         27   1A 009048E0 unw_is_signal_frame
         28   1B 00DB76C0 unw_local_addr_space
         29   1C 009048D0 unw_regname
         30   1D 00904860 unw_resume
         31   1E 009047A0 unw_set_fpreg
         32   1F 009046D0 unw_set_reg
         33   20 009047F0 unw_step

  Summary

        D000 .data
        1000 .eh_fram
       47000 .pdata
      2A0000 .rdata
       12000 .reloc
      B0D000 .text
        1000 .tls

The same Java code works successfully with cedar_java_ffi.dll built locally using

cargo build --features partial-eval --release --target x86_64-pc-windows-gnu

and forced using CEDAR_JAVA_FFI_LIB env variable.

The dumpbin for this dll shows the exported Java functions

dumpbin /EXPORTS dlls/cargo_build/cedar_java_ffi.dll
Microsoft (R) COFF/PE Dumper Version 14.42.34436.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file dlls\cargo_build\cedar_java_ffi.dll

File Type: DLL

  Section contains the following exports for cedar_java_ffi.dll

    00000000 characteristics
    67C9C304 time date stamp Thu Mar  6 18:45:08 2025
        0.00 version
           1 ordinal base
          14 number of functions
          14 number of names

    ordinal hint RVA      name

          1    0 00019870 Java_com_cedarpolicy_BasicAuthorizationEngine_callCedarJNI
          2    1 0001A030 Java_com_cedarpolicy_BasicAuthorizationEngine_getCedarJNIVersion
          3    2 0001E880 Java_com_cedarpolicy_formatter_PolicyFormatter_policiesStrToPretty
          4    3 0001B2D0 Java_com_cedarpolicy_model_policy_PolicySet_parsePoliciesJni
          5    4 0001AC80 Java_com_cedarpolicy_model_policy_Policy_parsePolicyJni
          6    5 0001C370 Java_com_cedarpolicy_model_policy_Policy_parsePolicyTemplateJni
          7    6 0001CA10 Java_com_cedarpolicy_model_policy_Policy_toJsonJni
          8    7 0001A720 Java_com_cedarpolicy_model_schema_Schema_parseCedarSchemaJni
          9    8 0001A190 Java_com_cedarpolicy_model_schema_Schema_parseJsonSchemaJni
         10    9 0001D430 Java_com_cedarpolicy_value_EntityIdentifier_getEntityIdentifierRepr
         11    A 0001DB00 Java_com_cedarpolicy_value_EntityTypeName_getEntityTypeNameRepr
         12    B 0001D7C0 Java_com_cedarpolicy_value_EntityTypeName_parseEntityTypeName
         13    C 0001E1B0 Java_com_cedarpolicy_value_EntityUID_getEUIDRepr
         14    D 0001DE50 Java_com_cedarpolicy_value_EntityUID_parseEntityUID

  Summary

        1000 .CRT
        3000 .bss
        1000 .data
        1000 .edata
        1000 .eh_fram
        2000 .idata
       43000 .pdata
      189000 .rdata
       10000 .reloc
      9E7000 .text
        1000 .tls
       FF000 .xdata

Expected behavior

The code works with bundled windows dll

Reproduction steps

See description

Code Snippet

package org.example;

import com.cedarpolicy.model.exception.InternalException;
import com.cedarpolicy.model.policy.PolicySet;

public class Main {
    public static void main(String[] args) throws InternalException {
        PolicySet.parsePolicies("");
    }
}

Log output

Exception in thread "main" java.lang.UnsatisfiedLinkError: 'com.cedarpolicy.model.policy.PolicySet com.cedarpolicy.model.policy.PolicySet.parsePoliciesJni(java.lang.String)'
	at com.cedarpolicy.model.policy.PolicySet.parsePoliciesJni(Native Method)
	at com.cedarpolicy.model.policy.PolicySet.parsePolicies(PolicySet.java:128)
	at org.example.Main.main(Main.java:8)

Additional configuration

No response

Operating System

Windows 10

Additional information and screenshots

No response

Activity

  1. changed the title [-]UnsatisfiedLinkError on Windows with bundled native cedar_java_ffi.dll[/-] [+]UnsatisfiedLinkError on Windows with bundled cedar_java_ffi.dll[/+] on Mar 6, 2025
  2. 01epa commented on Mar 7, 2025

    @01epa

    Got the same issue om my local windows machine

  3. muditchaudhary commented on Mar 25, 2025

    @muditchaudhary
    Contributor

    Thank you for pointing this out. We are looking into this and will provide an update soon.

  4. vixmemon commented on Mar 26, 2025

    @vixmemon

    Facing the same issue in Linux
    java.runtime.version=17.0.14+7-LTS,
    os.version=6.1.128,
    java.runtime.name=OpenJDK Runtime Environment,
    java.vm.vendor=Red Hat, Inc.,
    sun.arch.data.model=64,

    Caused by: java.lang.UnsatisfiedLinkError: Unable to cleanly find (or extract) library [cedar_java_ffi] as resource
    at com.fizzed.jne.JNE.loadLibrary(JNE.java:259) ~[jne-4.1.1.jar!/:4.1.1]
    at com.fizzed.jne.JNE.loadLibrary(JNE.java:225) ~[jne-4.1.1.jar!/:4.1.1]
    at com.cedarpolicy.loader.LibraryLoader.loadLibrary(LibraryLoader.java:41) ~[cedar-java-4.2.3-uber.jar!/:na]
    at com.cedarpolicy.value.EntityTypeName.(EntityTypeName.java:41) ~[cedar-java-4.2.3-uber.jar!/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.1.16.jar!/:6.1.16]

    org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:348) ~[spring-context-6.1.16.jar!/:6.1.16]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146) ~[spring-beans-6.1.16.jar!/:6.1.16]
    ... 41 common frames omitted

  5. muditchaudhary commented on Mar 27, 2025

    @muditchaudhary
    Contributor

    @vixmemon Your issue might be related to #279. It was resolved in release 4.3. Can you try updating your CedarJava to the latest version (4.3.1) and see if that resolves your issue.

  6. vixmemon commented on Mar 27, 2025

    @vixmemon

    I have tried latest version. this issue is in latest version @muditchaudhary

  7. muditchaudhary commented on Mar 27, 2025

    @muditchaudhary
    Contributor

    @vixmemon Can you create a separate issue for the problem you have been encountering with more details (E.g., CedarJava version, OS, Arch, etc.). The issue with linking in Windows is because of a different problem. Thanks!

  8. vixmemon commented on Mar 27, 2025

    @vixmemon

    new bug created #314

  9. vixmemon commented on Mar 28, 2025

    @vixmemon

    I tested it on both,
    on windows and on linux.
    Linux is the environment where our applications are deployed, while development goes on in Windows.

  10. muditchaudhary commented on Mar 28, 2025

    @muditchaudhary
    Contributor

    @vixmemon Could you confirm if you're getting the exact same error on both Linux and Windows machines? I ask because CedarJava handles platforms differently - on Windows it looks for the DLL file for cedar-java-ffi, while on Linux it looks for the .so file.

    For Windows, you might be using this workaround (You should not use this workaround on Linux):

    1. Creating a DLL using cargo build --features partial-eval --release --target x86_64-pc-windows-gnu
    2. Setting the CEDAR_JAVA_FFI_LIB environment variable to use the generated DLL

    Are you using this same Windows-specific approach on Linux? Could you share what steps you're taking specifically for Linux, so that I can recreate this issue? This would help us troubleshoot the issue.

  11. vixmemon commented on Mar 28, 2025

    @vixmemon

    Facing same issue on linux with latest -uber dependency.
    Also tried 'com.cedarpolicy:cedar-java:4.3.1:uber'

    Issue in Linux
    Caused by: java.lang.UnsatisfiedLinkError: Unable to cleanly find (or extract) library [cedar_java_ffi] as resource
    at com.fizzed.jne.JNE.loadLibrary(JNE.java:259) ~[jne-4.1.1.jar!/:4.1.1]
    at com.fizzed.jne.JNE.loadLibrary(JNE.java:225) ~[jne-4.1.1.jar!/:4.1.1]
    at com.cedarpolicy.loader.LibraryLoader.loadLibrary(LibraryLoader.java:41) ~[cedar-java-4.2.3-uber.jar!/:na]
    at com.cedarpolicy.value.EntityTypeName.(EntityTypeName.java:41) ~[cedar-java-4.2.3-uber.jar!/:na]

    I tried to use the .so file by using environment variable and absolute path of the .so file.
    Caused by: java.lang.UnsatisfiedLinkError: /opt/libcedar_java_ffi.so: /opt/libcedar_java_ffi.so: cannot open shared object file: No such file or directory (Possible cause: can't load AARCH64 .so on a AMD 64 platform)

    A working .so file for AMD64 arch for linux would be helpful

  12. muditchaudhary commented on Mar 28, 2025

    @muditchaudhary
    Contributor

    Got it. Let me try it on an AMD64 machine and get back to you.

  13. muditchaudhary commented on Mar 28, 2025

    @muditchaudhary
    Contributor

    @vixmemon I tried running this cedar-java example on a Linux AMD64 machine (which is an x86_64 architecture) and I wasn't able to recreate the error you have been receiving.

    $ lscpu
    Architecture:        x86_64
    CPU op-mode(s):      32-bit, 64-bit
    Byte Order:          Little Endian
    CPU(s):              48
    On-line CPU(s) list: 0-47
    Thread(s) per core:  1
    Core(s) per socket:  48
    Socket(s):           1
    NUMA node(s):        1
    Vendor ID:           AuthenticAMD
    CPU family:          25
    Model:               17
    Model name:          AMD EPYC 9R14
    Stepping:            1
    CPU MHz:             3706.422
    BogoMIPS:            5199.99
    Hypervisor vendor:   KVM
    Virtualization type: full
    L1d cache:           32K
    L1i cache:           32K
    L2 cache:            1024K
    L3 cache:            32768K
    NUMA node0 CPU(s):   0-47
    

    I followed the steps below to check if CedarJava works on my Linux AMD64 machine:

    git clone https://github.com/cedar-policy/cedar-examples.git && cd cedar-examples/cedar-java-partial-evaluation
    
    ./gradlew run
    

    Can you try running this exact same example on your Linux machine and let us know if you are still getting the error. If you still see the same error, can you share the output of lscpu command? Thanks!

  14. vixmemon commented on Mar 28, 2025

    @vixmemon

    @muditchaudhary i tested again on linux with 4.3.1 and it worked for me. So let's fix windows issue maybe.

  15. muditchaudhary commented on Apr 7, 2025

    @muditchaudhary
    Contributor

    After investigation, we found that while native library bundling was implemented in #104, it was not tested for Windows environments and has not functioned on that platform since implementation. Rather than treating this as a bug fix, we've categorized it as a potential future enhancement. While we don't have a specific timeline for implementing Windows support, we welcome community contributions.

    Temporary Workaround for Windows Users:

    1. Clone the cedar-java repository
    2. Build CedarJavaFFI with the following command:
    cargo build --features partial-eval --release --target x86_64-pc-windows-gnu
    1. Set the CEDAR_JAVA_FFI_LIB environment variable to point to the generated DLL

    We'll keep this issue open to track progress on proper Windows support for native library bundling.

  16. added and removed
    bugSomething isn't working
    on Apr 7, 2025
  17. abalabolov commented on Jul 24, 2025

    @abalabolov

    Hello
    Any updates?

    we've categorized it as a potential future enhancement was not a good idea.

    This is built CedarJavaFFI using solution above. It contains exported Java functions and works.
    It is .7z so replace .zip to .7z before usage because Github doesn't allow to upload .7z.
    cedar_java_ffi.zip

    Another issue is that principal in [Role::"X", Role::"Y"] doesn't work for any OS libs. Claude says: "Cedar's Java JNI binding doesn't support the set notation [Role::"X", Role::"Y"] in the principal position. This is a limitation of the Java Cedar library (the Rust/native Cedar supports it)."

  18. raja777m commented on Feb 10, 2026

    @raja777m

    Hello Any updates?

    we've categorized it as a potential future enhancement was not a good idea.

    This is built CedarJavaFFI using solution above. It contains exported Java functions and works. It is .7z so replace .zip to .7z before usage because Github doesn't allow to upload .7z. cedar_java_ffi.zip

    Another issue is that principal in [Role::"X", Role::"Y"] doesn't work for any OS libs. Claude says: "Cedar's Java JNI binding doesn't support the set notation [Role::"X", Role::"Y"] in the principal position. This is a limitation of the Java Cedar library (the Rust/native Cedar supports it)."

    1. can we make the dll work on linux environment, because I have some tests that are failing because the Cedar native library (cedar_java_ffi) for Linux is missing. My libs folder only contains the Windows DLL which you provided, but my CI runs on Linux.
      Linux: libcedar_java_ffi.so is missing.

    2. I had to skip the tests for the time being.

  19. muditchaudhary commented on Feb 11, 2026

    @muditchaudhary
    Contributor

    @abalabolov Unfortunately, we are unable to prioritize windows cross-platform support. We have added additional instructions for the users to build CedarJava for Windows locally. Apologies for any inconvenience.

    Another issue is that principal in [Role::"X", Role::"Y"] doesn't work for any OS libs. Claude says: "Cedar's Java JNI binding doesn't support the set notation [Role::"X", Role::"Y"] in the principal position. This is a limitation of the Java Cedar library (the Rust/native Cedar supports it)."

    This is not a Cedar feature. Principals and Resources do not support in operation with set notation.

    For reference, below is the Cedar policy grammar for Principal. [Cedar policy grammar]

    Principal ::= 'principal' [(['is' PATH] ['in' (Entity | '?principal')]) | ('==' (Entity | '?principal'))]
    
  20. muditchaudhary commented on Feb 11, 2026

    @muditchaudhary
    Contributor

    @raja777m

    can we make the dll work on linux environment, because I have some tests that are failing because the Cedar native library (cedar_java_ffi) for Linux is missing. My libs folder only contains the Windows DLL which you provided, but my CI runs on Linux.
    Linux: libcedar_java_ffi.so is missing.

    Thank you for reaching out. No, DLLs cannot be supported on Linux.

    To help you further, a few questions:

    1. May I know your setup (OS, Architecture) for CI?
    2. Are you planning to serve CedarJava for a Linux platform or do you only need to support it for Windows?
    3. Are you consuming CedarJava as a dependency from Maven or are you building CedarJava from source in the CI process? If you are building it from the source, is there a particular reason why you want to build CedarJava from source?
  21. raja777m commented on Feb 23, 2026

    @raja777m

    May I know your setup (OS, Architecture) for CI? My PIP API is configured on lambdas. so, when the end points get hit, it spuns out a lambda.
    Are you planning to serve CedarJava for a Linux platform or do you only need to support it for Windows? no windows app, my apps are linux based only.
    Are you consuming CedarJava as a dependency from Maven - yes, I tried the 4.8.0 uber gradle dependency and have the same issue as this ticket.
    so, I used uber jar, excluded the ffi.dll that comes with it, and included in the libs folder and calling it from the build.gradle

    the thing is, I did not test the ...ffi.so that came with the 4.8.0:uber. Will test it this week and update if I have any further issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions