This product is not supported for your selected Datadog site. ().
Metadata
ID:java-code-style/avoid-using-native-code
Language: Java
Severity: Notice
Category: Code Style
Description
When Java applications use native code, typically through the Java Native Interface (JNI) and methods like System.loadLibrary() or System.load(), it introduces a strong dependency on platform-specific binaries. This practice significantly reduces the portability of the application, as the native libraries must be compiled and distributed for each target operating system and architecture. It also increases deployment complexity, makes debugging more challenging, and can lead to instability or crashes if native code interactions are not meticulously managed.
How to Remediate
To enhance portability and maintainability, favor pure Java solutions over native code whenever possible. If interacting with system-specific features or achieving critical performance gains necessitates native calls, consider abstracting them behind an interface to minimize their direct impact on the codebase. Prioritize using well-established, cross-platform libraries or external services that handle native interactions internally, rather than directly managing System.loadLibrary() calls within your application logic.
publicclassBar{publicvoidbaz(){System.out.println("Executing pure Java code without native dependencies.");// No System.loadLibrary or System.load calls here}}
Seamless integrations. Try Datadog Code Security
Datadog Code Security
Try this rule and analyze your code with Datadog Code Security
How to use this rule
1
2
rulesets:- java-code-style # Rules to enforce Java code style.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Security scans to your CI pipelines