NetBeans java.time code completion: missing zone ID list
0 reputation · 12 Aug 2024, 18:22 UTC
0 reputation · 12 Aug 2024, 18:22 UTC
To enable automatic completion of all available ZoneId identifiers when invoking ZonedDateTime.now(ZoneId.of("…")) in NetBeans.
NetBeans’ built‑in code completion currently offers only a limited set of zone IDs. Developers must type zone identifiers manually, which is error‑prone for large or uncommon zones. It is unclear whether this behavior is intentional, configurable, or dependent on JDK version or project settings.
ZoneId.getAvailableZoneIds()?java.time completion that would explain this omission?34775 reputation · 13 Aug 2024, 02:46 UTC
NetBeans will show the complete list of ZoneId identifiers only when the JDK source that contains the java.time API is attached to the platform the IDE uses. If the source is missing or the IDE is pointing at a JDK that does not ship with src.zip, the completion list is limited or empty.
src.zip, it cannot enumerate ZoneId.getAvailableZoneIds().
Tools → Java Platforms.
Source field. It should point to a valid src.zip that ships with the JDK.
Source path is empty or points to a non‑existent file:
jdk-17.0.8-src.zip from the official site).
Attach Source in the platform dialog and select the downloaded src.zip.
Properties → Sources and confirm that the Java Platform matches the one you just verified.
ZoneId.of(" and press Ctrl+Space. The drop‑down should now list all known zone IDs such as America/New_York, Europe/London, etc.If you are running NetBeans 8.2 or earlier, consider upgrading to the latest stable release (currently 18). Newer IDEs bundle the JDK source automatically and enable java.time completion by default.
To fine‑tune the recommendation, could you confirm which NetBeans version and JDK you are using? Knowing whether the JDK source is already attached will help decide if a simple attachment or an IDE update is required.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 13 Aug 2024, 00:15 UTC
While attaching the src.zip helps the IDE resolve API signatures, it is important to note that ZoneId identifiers are derived from the Time Zone Database (TZDB). Because these IDs are effectively data rather than static code constants, NetBeans may not reflect updates to the TZDB if the JDK was updated via a patch without a full IDE re-index.
If completion remains limited after attaching sources, verify the actual available IDs in your current runtime environment using a simple test snippet:
System.out.println(java.time.ZoneId.getAvailableZoneIds());
If the runtime list is more extensive than the IDE suggestions, the issue is likely a stale index. A full restart or clearing the NetBeans cache (located in the AppData/Local/NetBeans or ~/.cache/netbeans directory) can force the IDE to synchronize with the current JDK's TZDB version.