By NHI Mgmt Group Editorial TeamDomain: Cyber SecuritySource: SonarPublished June 9, 2026

TL;DR: Java.time bugs often compile, pass tests, and still return silently wrong answers, especially when LocalDateTime is used across timezones or when tests call now() without an injected Clock, according to Sonar. The risk is not just correctness drift but downstream billing, SLA, and scheduling errors that look plausible enough to survive review.


At a glance

What this is: This is an analysis of SonarQube’s new java.time rules, which target silent time-handling bugs such as timezone-blind duration math, non-deterministic clocks, and identity comparisons on value types.

Why it matters: It matters to IAM and broader security practitioners because the same design flaw appears in identity and access systems that rely on time-bound logic, such as token expiry, session validation, and audit timing.

By the numbers:

👉 Read Sonar’s analysis of silent java.time bugs and the new rule set


Context

Java time handling fails most often when code assumes a local timestamp is the same thing as elapsed time. That assumption breaks as soon as a calculation crosses zones, daylight saving changes, or test environments with different clocks, and the result can look valid while still being wrong. In identity-heavy systems, the same pattern shows up when token expiry, session windows, and audit timing are implemented without an explicit time source.

The governance problem is that compilers and tests often validate the syntax of time logic, not its real-world meaning. A silent error can survive code review, pass unit tests, and still affect billing, scheduling, or access decisions. For teams managing identity lifecycles and non-human credentials, that makes time a control plane concern rather than a formatting detail.


Key questions

Q: How should security teams handle time-based logic in token expiry and session controls?

A: Use explicit, zone-aware time types and inject a controllable Clock into any logic that governs expiry, renewal, or revocation. That keeps tests deterministic and prevents silent drift when code runs across timezones, daylight saving changes, or CI environments with different timing behaviour.

Q: Why do local timestamps create risk in identity and access systems?

A: Local timestamps record wall-clock values without timezone context, so elapsed-time calculations can look correct while still being wrong. In identity systems, that can extend session windows, skew revocation timing, or misstate audit evidence when a calculation crosses zones or relies on system defaults.

Q: What do teams get wrong about comparing Java value-based types?

A: They often compare references instead of values, which makes code appear to work in tests and fail in production. For Instant, Optional, and wrapper types, use equals() for semantic equality and avoid identity checks unless the object reference itself is the intended signal.

Q: How do you know if time handling is safe enough for security decisions?

A: The best signal is repeatable behaviour under fixed clocks and multiple zones. If tests only pass when they depend on the system clock, or if access and expiry logic changes under timezone shifts, the implementation is not yet safe for security-critical use.


Technical breakdown

Why LocalDateTime breaks duration math across zones

LocalDateTime stores a calendar date and wall-clock time, but no timezone offset. That makes it useful for display and fragile for measuring elapsed time, because duration APIs such as ChronoUnit.HOURS.between() can only subtract the fields they see. If two timestamps come from different zones, the code still returns a number, but the number reflects clock-face subtraction rather than physical elapsed time. That is why a flight, billing window, or access period can look reasonable and still be wrong. The bug is structural: the type system allows the operation, but the domain meaning is missing.

Practical implication: Treat any elapsed-time calculation that uses LocalDateTime as suspect unless both endpoints are converted to zone-aware types first.

Why .now() without a Clock makes tests non-deterministic

Calling Instant.now() or similar methods without an injected Clock ties program behaviour to the system clock, CPU timing, and JVM warmup state. That means the same test can pass once and fail later, not because the logic changed, but because two time samples collapsed into the same instant or drifted by a few microseconds. Deterministic tests need a fixed or controllable time source so that expiry checks, token logic, and lifecycle transitions can be asserted repeatably. Static analysis is useful here because the failure mode often appears only under load or in CI.

Practical implication: Inject a Clock into any code that makes security or lifecycle decisions based on time.

Why value-based types should not use identity comparison

Value-based classes such as Instant, Optional, and primitive wrappers represent content, not object identity. Using == on them compares heap references, not the value they hold, so two objects that represent the same instant can still compare false. In some cases the JVM caching behaviour of wrappers makes this mistake appear to work for small values and fail for larger ones, which is why it survives testing. The same issue appears with System.identityHashCode(), which is also meaningless for value semantics. Sonar’s rule set generalises this lesson beyond time types because the underlying bug is about confusing identity with value.

Practical implication: Use equals() for value-based types and reserve identity checks for cases where object reference is the actual design requirement.


NHI Mgmt Group analysis

Silent temporal drift is a governance problem, not a formatting bug. The article shows how LocalDateTime can produce plausible but incorrect results that survive review and unit tests. That matters to IAM and NHI governance because token expiry, session validity, and access windows all depend on trustworthy time semantics. If a control decision is time-based, the clock source and timezone model are part of the control design, not an implementation detail.

Time-related defects become security defects when they govern access lifecycles. A test that passes because two timestamps are close enough can still hide a privilege window that is too long or too short. For NHI programmes, that maps directly to service account rotation, secret expiry, and offboarding logic, where bad time handling can keep credentials usable longer than intended. Practitioners should treat time correctness as a prerequisite for lifecycle control.

AI-assisted coding amplifies the risk because simple types are over-recommended. The article notes that coding tools default to LocalDateTime because it is the easier pattern to generate. That creates a subtle governance debt: generated code may satisfy syntax and style checks while skipping explicit time-source design. Teams using AI coding tools should review time-dependent code with the same scrutiny they apply to secret handling and privilege boundaries.

Deterministic time is a control pattern that deserves naming. The article points to a broader time trust gap, where systems trust local clocks and wall-clock types more than they trust explicit, testable time sources. In identity programmes, that gap shows up in session expiry, revocation timing, and audit evidence. Closing it means treating time as governed infrastructure, not incidental logic.

What this signals

The broader signal for identity programmes is that time correctness belongs inside governance design. If revocation, expiry, or rotation is measured with the wrong clock model, the control still exists on paper but fails in practice. Teams should review whether their identity services use explicit time sources, zone-aware logic, and deterministic tests before they assume lifecycle controls are reliable.

Time trust gap: access and lifecycle systems often trust local timestamps more than governed time sources, which creates hidden failure modes in access reviews, audit evidence, and automated revocation. That is particularly relevant where NHIs rely on short-lived credentials and precise expiry semantics. NHI and IAM teams should treat time handling as part of control validation, not just application development.

For practitioners, the next step is to test identity workflows under multiple zones, fixed clocks, and boundary conditions such as DST changes or immediate expiry. If those tests uncover drift, the issue is not cosmetic. It means the access model can misbehave at exactly the point where governance expects it to be most reliable.


For practitioners

  • Convert elapsed-time logic to zone-aware types Review every duration calculation that uses LocalDateTime or similar local types. Convert both endpoints to ZonedDateTime or Instant before comparing, especially where the result affects billing, SLA measurement, token expiry, or scheduled access windows.
  • Inject a controllable Clock into security logic Require an explicit Clock in services that decide expiry, renewal, or access revocation. Use fixed clocks in tests so lifecycle assertions are deterministic and do not depend on JVM warmup or platform timing.
  • Ban identity comparisons on value-based types Add static analysis rules and code review checks for == and System.identityHashCode() on Instant, Optional, and wrapper types. Reserve identity comparisons for genuine object identity cases and use equals() for semantic equality.

Key takeaways

  • LocalDateTime can produce believable numbers that are still wrong, which makes time handling a governance issue whenever access or billing depends on elapsed time.
  • Injected clocks and zone-aware timestamps turn security-sensitive time logic into something tests can verify and operations can trust.
  • Identity teams should review time semantics in session, expiry, and rotation workflows before treating automation as dependable.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST CSF 2.0, NIST SP 800-53 Rev 5, CIS Controls v8 and NIST AI RMF set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0PR.AC-1Time-bound access logic affects authentication and access enforcement.
NIST SP 800-53 Rev 5IA-5IA-5 governs authenticator management, including expiration and renewal timing.
CIS Controls v8CIS-5 , Account ManagementAccount lifecycle timing depends on reliable revocation and offboarding.
NIST AI RMFMANAGEAI-assisted coding can amplify insecure time-handling patterns.

Use CIS-5 to validate that offboarding and expiry processes are deterministic and auditable.


Key terms

  • LocalDateTime: A date and time type that stores wall-clock values without a timezone or offset. It is useful for representing a local appointment or display value, but it is unsafe for measuring elapsed time across zones because the physical meaning of the timestamp is incomplete.
  • Clock: An injectable source of time used to control how code reads the current instant. In security-sensitive systems, a Clock makes expiry, renewal, and revocation logic testable and repeatable, which helps prevent false confidence from tests that depend on the system clock.
  • Value-Based Type: A type whose meaning comes from the value it holds rather than the memory location of the object. Comparing these types by reference can produce unstable behaviour, especially in Java APIs where equals() expresses the real semantic relationship and identity checks do not.

What's in the full article

Sonar’s full analysis covers the rule mechanics and code patterns this post intentionally leaves at a higher level:

  • Rule-by-rule examples for detecting timezone-blind duration math and non-deterministic clock usage
  • SonarQube Cloud and Server rollout details for the eight java.time rules
  • False-positive handling notes for test code and assertion patterns
  • The exact static analysis patterns used to catch identity comparisons on value-based types

👉 Sonar’s full post shows the code patterns, rule IDs, and fix examples behind the findings.

Deepen your knowledge

The NHI Foundation Level course, the industry's only accredited NHI security programme, covers NHI governance, identity lifecycle, and secrets management. It helps practitioners connect control design to the operational realities that affect access, expiry, and offboarding.
NHIMG Editorial Note
Published by the NHIMG editorial team on August 19, 2026.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org