Backend Development 8 min read

Introducing the Java Development Manual (Taishan Edition): Unified Error Codes, Leap‑Year Pitfalls, SQL Alias, Code‑Style Tips, and Ternary‑Operator NPE Issues

The new Java Development Manual (Taishan Edition) adds 34 rules and revises 90 descriptions, introduces a unified five‑character error‑code scheme, warns about stream‑toMap and ternary‑operator null‑pointer traps, highlights leap‑year and SQL alias bugs, and recommends readability tweaks such as blank lines after returns.

Amap Tech
Amap Tech
Amap Tech
Introducing the Java Development Manual (Taishan Edition): Unified Error Codes, Leap‑Year Pitfalls, SQL Alias, Code‑Style Tips, and Ternary‑Operator NPE Issues

The "Java Development Manual (Taishan Edition)" has been released, adding 34 new rules and revising 90 descriptions, including a complete solution for unified error‑code design.

One of the highlighted pitfalls is the misuse of stream.Collectors.toMap() , which can throw a NullPointerException when duplicate keys appear or when values are null . The author shares a personal experience of falling into this trap.

The new error‑code scheme uses a five‑character string split into two parts: a source identifier (A, B, or C) and a four‑digit numeric code. Sources are defined as:

A – errors caused by the user (e.g., invalid request parameters).

B – errors caused by the system or business logic.

C – errors caused by third‑party services (e.g., CDN failures).

Advantages of this unified code include fast traceability, easy memorability, and standardized communication across services.

Another common bug discussed is the "leap‑year bug" where developers hard‑code the number of days in a year as 365. This leads to premature cache expiration and database overload during leap years. The recommendation is to use java.time.LocalDate for accurate year‑day calculations.

In SQL development, the manual stresses the importance of using table aliases to avoid column‑name collisions in multi‑table queries. Without aliases, ambiguous column references can cause hard‑to‑debug bugs.

For code readability, the author suggests inserting a blank line after a return or throw statement when a method exceeds ten lines. This provides visual breathing space for future readers.

The ternary operator can also cause unexpected NullPointerException due to automatic unboxing. The following example demonstrates the issue:

Integer a = 1;
Integer b = 2;
Integer c = null;
Boolean flag = false;
Integer result = (flag ? a * b : c);

When flag is false, the expression evaluates to c , which is null . The unboxing of null triggers an NPE.

The manual concludes with an invitation to download the full "Taishan" version for detailed guidelines, and hints at a future "Songshan" edition.

backendjavaSQLcode-styleError Codesternary operator
Amap Tech
Written by

Amap Tech

Official Amap technology account showcasing all of Amap's technical innovations.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.