You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] New Rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe #5923
Code Sample: This should include code, that should be flagged by the rule. If possible, the "correct" code
according to this new rule should also be demonstrated.
In the bad code below, 128 bytes of memory are allocated but then arbitrary strings are written which could easily go over the 128 bytes limit.
In general I think that any use of sun.misc.Unsafe or jdk.internal.misc.Unsafe should be flagged as a security concern. I know that the DontImportSun already covers sun.misc.Unsafe but it is wider in its scope (all of sun.*) and it doesn't explain the security risk so it might be easily dismissed by someone who doesn't know the particular security implications of sun.misc.Unsafe. A security-specific rule including both sun.misc.Unsafe and jdk.internal.misc.Unsafe seems more appropriate.
I can create a PR for this but I wanted to discuss it first. See a working draft of XPath rule here.
changed the title [-]Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/-][+][java] Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/+]on Nov 20, 2025
changed the title [-][java] Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/-][+][java] New rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/+]on Nov 20, 2025
changed the title [-][java] New rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/-][+][java] New Rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/+]on Jan 29, 2026
Activity
elharo commentedon Nov 13, 2025
JDK already warns about this. I'm not sure why PMD should duplicate that.
[-]Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/-][+][java] Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/+][-][java] Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/-][+][java] New rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/+][-][java] New rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/-][+][java] New Rule: Catch usages of sun.misc.Unsafe or jdk.internal.misc.Unsafe[/+]