Go to Java Migration: Surviving Nulls, Zero Values, and Traffic Cutover
This article shares practical lessons from migrating a Go business system to Java (JDK 17, Spring Boot 3), covering language differences in nil/null handling, error propagation, time zero values, database updates, concurrency, JSON serialization, and a phased gateway traffic cutover strategy with automated API comparison testing.
Reading font

Framework Versions
The team chose JDK 17 and Spring Boot 3 for the new Java stack, providing a stable foundation for layering, configuration, graceful shutdown, and testing that avoids major upgrades for years. Client libraries for message queues, search, cache, and service discovery were kept at versions compatible with the existing server-side protocols; upgrading only one side would break connectivity because proto definitions and code-generation plugins are tightly coupled. These version constraints were documented in the project README, and no middleware upgrades were attempted during migration.
Language Differences Causing Exceptions
Go's lenient handling of zero values and nil slices contrasts sharply with Java's strict null semantics, leading to frequent NullPointerExceptions in migrated code.
Empty collections: In Go, a nil slice can be iterated and appended to (length 0). In Java, iterating a null list, calling size(), or passing it to protobuf's addAll throws NPE. Even when outer code checks for non-null, conversion logic may turn an empty list into null, which addAll rejects.
Map missing keys: Go returns zero values; Java's get returns null. Assigning that null to primitive long, int, or boolean triggers unboxing NPE.
Error handling: Go returns errors as values. Translating to Java catch blocks often collapses distinct error types (parameter errors, business errors) into a generic internal error, changing the error codes and messages seen by callers. Spring's default transaction rollback only triggers on runtime exceptions; checked exceptions caught and swallowed allow the transaction to commit. Methods needing rollback on any exception must declare @Transactional(rollbackFor = Exception.class).
Time zero values: Go's time.Time zero is year 1 AD; Java and databases typically use 1970-01-01 or null. Mistaking one for the other treats an unset field as a real timestamp. LocalDateTime without an explicit zone uses the JVM's default (often UTC in containers), causing an 8-hour offset in production.
Database updates: Go struct-based updates often skip zero/false/empty-string fields. Java persistence frameworks (e.g., MyBatis) skip only null, writing 0, false, and empty strings. Column names must match the original model's @Column annotations; using a field alias as the column name breaks MySQL schema validation even if in-memory database tests pass. Handwritten SQL with camelCase aliases may silently return null on mismatch. CAST and date functions differ between H2 and MySQL, so tests must run against real MySQL.
Concurrency: Go's lightweight goroutines encourage ad-hoc spawning. In Java, creating a new thread pool per request leaks threads and prevents graceful shutdown. Thread pools must be singletons with bounded queues, and shutdown must await task completion. Go's defer for unlocking maps to Java's finally blocks; missing unlocks cause deadlocks.
HTTP clients: Go returns response bodies even for 4xx status codes. Some Java clients throw exceptions and discard the body, breaking retry logic and error-code inspection.
JSON serialization: Go's omitempty omits 0, false, and empty strings. Jackson configured with NON_NULL only omits null, so 0 and false appear in output. BigDecimal.equals considers scale (1.0 != 1.00); use compareTo for value comparison. Go counts string length in bytes; Java's length() counts UTF-16 code units, diverging on emojis and rare characters. Go serializes map keys in sorted order; Java's HashMap has no order, breaking downstream consumers that depend on key ordering.
After each migrated business module, the team reviews a checklist: empty collections, unboxing, transaction rollback, time zero values, zero-value DB writes, column names, thread pools, and JSON zero handling.
Establishing Standards First
Before large-scale code migration, the team defined concise rules for layering, package/class naming, explicit input/output types, BigDecimal for money, time with zone, transaction placement in the application layer, and distinct semantics for empty list vs. null. These rules were codified in architecture tests (using tools like ArchUnit) that verify dependency direction, controller placement, return types, and entity layering. Existing violations were frozen; new violations fail the build. The same rule set feeds both human reviewers and code assistants, ensuring consistent generated code. Deferring this step would require massive refactoring later (moving packages, widening return types, reworking null semantics during integration).
Code Assistant-Driven Migration
Business logic translation, boilerplate generation, and test scaffolding were largely delegated to an AI code assistant. Humans defined the migration scope per batch and performed final behavioral verification. For a given business domain, the assistant received the entry points, route registrations, error codes, and verified request/response samples, with explicit instructions not to alter protocols, merge endpoints, or change business rules. Generated code was reviewed file-by-file against the original to ensure no missing branches or extra fields.
Breaking Work by Business Domain
Large batches (hundreds of endpoints) caused the assistant to drop later branches, merge distinct errors, and invent fields. The team therefore split work by business capability. Each domain got a checklist: active routes and methods, authentication, upstream/downstream dependencies, scheduled jobs, write operations. Deprecated routes were marked and excluded. Shared infrastructure (clients, error mappers, authentication context) was migrated once and reused.
Unit Testing
Unit tests were also mostly assistant-generated, with humans selecting the scenarios. Integration traffic rarely exercises empty collections, missing map keys, zero-value updates, error branches, time zero values, or lock/thread-pool leaks, so these were explicitly covered in unit tests. Assertions mirrored Go's original behavior: whether an empty list serializes as an empty array or is omitted, whether an error is a parameter error or internal error, whether a zero update is skipped or persisted. Human review focused on assertion correctness. Tests running on in-memory databases (H2) must have schema aligned with real MySQL; entity column-name mistakes often pass in H2 but fail on MySQL.
API Comparison Testing
Automated diff testing replayed the same request against both Go and Java services, comparing status codes, business codes, field presence, and values. Dynamic fields (trace IDs, timestamps, pre-signed URLs) were excluded from value comparison but checked for presence. Edge cases included unauthorized, expired token, invalid parameters, downstream timeout, unique-key conflict, empty data, and partial failure. Read-only endpoints used production data; write endpoints used isolated data or stubs to avoid double-writes. Core flows (order, payment, audit, state transitions) received additional manual verification in a staging environment. Discrepancies were traced back to Go source before fixing Java.
Gateway Traffic Cutover
Both services ran simultaneously. Traffic was shifted at the gateway. On launch day, office egress IPs were routed to Java first, allowing the team to exercise real accounts through normal, rejected, boundary, and error flows while production users stayed on Go. After validation, production traffic was incrementally increased by percentage, monitoring error rates, latency, and business codes. Rollback was a single gateway rule change. A rollback drill was performed beforehand: stop Java, revert traffic to Go, verify tokens and routes still work. Scheduled jobs were stopped on the old side, allowed to finish, then started on the new side. Service shutdown waited for in-flight requests and batch tasks in thread pools to complete, preventing half-written data.
About this article
For attribution, corrections or content rights, contact