Assumenosideeffects is a ProGuard and R8 directive that tells the optimiser to treat a method as having no side effects. It allows the tool to remove calls, inline code, or discard unused results when the method’s return value is not needed, which can change runtime behaviour if applied incorrectly.
What the directive means in practice
assumenosideeffects is a code-optimisation hint, not a semantic guarantee. It tells ProGuard or R8 that a method can be treated as if calling it has no observable effect, which can enable dead-code removal, constant propagation, or call elimination when the return value is unused. The term matters because the optimiser is making a behaviour-changing assumption about code that may still be relied on at runtime.
Where it is used in optimisation pipelines
This directive usually appears in build-time shrink and obfuscation rules, where the goal is to reduce app size and remove code paths that look unused. It is most useful for logging, tracing, debug-only helpers, or wrappers whose outputs are intentionally ignored in production builds. The trade-off is that any method later found to have side effects, such as state changes, I/O, or security-relevant checks, can be removed in ways the developer did not intend.
Why incorrect assumptions create subtle failures
The risk is not just that a method disappears. The optimiser can also inline or reorder code around the assumption, so a bad rule may change control flow in places that are hard to notice in testing. That makes the directive especially sensitive when the method participates in validation, telemetry, feature gating, integrity checks, or audit logging, because the runtime behaviour can diverge from the source code a reviewer expects to see.
How to reason about safe usage
The safest way to think about this rule is to apply it only to methods whose outputs are genuinely disposable and whose execution cannot affect program state, security posture, or user-visible behaviour. In practice, that means reviewing the method body, its transitive calls, and any dependencies on timing, randomness, caching, or external systems before assuming it is side-effect free. Treat the rule as a build-time contract: if the contract is wrong, the optimiser will trust it.
Risk and Threat Considerations
Incorrect assumenosideeffects rules can create silent integrity failures, because the optimiser may remove code that was actually enforcing policy, recording events, or updating state. The failure is often hard to detect during review, since the source still appears to contain the logic even when the compiled output no longer does.
Failure mechanism: A method is marked as side-effect free even though it mutates state, emits security logs, performs validation, or influences later control flow, so the optimiser strips or bypasses behaviour that the application still depends on.
Impact: The resulting binary can lose checks, logging, or state transitions, which may weaken auditability, break application logic, or create security gaps that only appear after deployment.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP ASVS, CIS Controls v8 and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V15 — Secure Coding and Architecture | Optimizer rules can alter runtime behaviour, so secure design review should cover build-time code transformation risks. |
| Recommendation — Review shrinker rules for behaviour changes and verify that optimisation does not remove security-relevant logic. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Secure build and release practices must account for code transformations that change shipped application behaviour. |
| Recommendation — Validate release builds to ensure optimisation rules do not remove required checks or logging. | ||
| NIST SP 800-53 Rev 5 | SA-11 — Developer Testing and Evaluation | Testing must confirm that transformed code still behaves as intended after optimisation rules are applied. |
| Recommendation — Test release artifacts after obfuscation or shrinking to confirm compiled behaviour matches security intent. | ||
Practitioner Guidance
What to watch for: Use this directive only after confirming that the method and every relevant call path are truly non-observable in the compiled application. For methods near security, accounting, telemetry, or feature-control logic, prefer explicit verification over optimiser assumptions, because the cost of a false positive is a behaviour change that build tests may not catch.
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 3, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org