I built a practical null-safety solution for Java #190123
Replies: 2 comments 2 replies
|
This is a really clean idea. Bringing Kotlin-style null safety (?., ?:) to plain Java without touching the JVM is genuinely useful, especially for teams stuck on large Java codebases who can't just migrate overnight. How does JADEx handle interop with existing libraries that return raw Object or unannotated types? Does it treat those as nullable by default? The compilation output being standard Java is smart — it means CI pipelines, IDEs, and existing tooling don't need to change at all. |
|
I would start by checking how this integrates with standard build pipelines. Since JADEx introduces new syntax, does it run as a Maven or Gradle plugin wrapping I am also curious about how you handle stack traces after source transformation. If the What is the measured performance overhead of |
Uh oh!
There was an error while loading. Please reload this page.
Select Topic Area
Show & Tell
Body
JADEx (Java Advanced Development Extension) is a safety layer that makes Java safer by adding
Null-SafetyandFinal-by-Defaultsemantics without modifying the JVM.Null-Safety
NullPointerException (NPE) is one of the most common sources of runtime failures in Java applications.
Although modern Java provides tools such as
Optionaland static analysis, null-related bugs are still fundamentally a runtime problem in most Java codebases.JADEx addresses this problem by introducing explicit nullability into the type system and enforcing safe access rules at compile time.
In JADEx:
Type→ non-nullable by defaultType?→ nullable?.→ null-safe access operator?:→ Elvis operator (fallback value)This design ensures that developers must explicitly acknowledge and handle nullable values before accessing them.
For example:
When compiled by JADEx, this code is translated into standard Java:
JADEx compiles null-safe expressions into standard Java using a small helper API(SafeAccess).
In this example:
nameis explicitly declared as nullable.The
?.operator safely accessestoLowerCase()only if name is not null.The
?:operator provides a fallback value if the result is null.Instead of writing repetitive null-check logic such as:
JADEx allows the same logic to be expressed safely and concisely.
Most importantly, JADEx prevents unsafe operations at compile time.
If a nullable variable is accessed without using the null-safe operator, the compiler will report an error.
This approach shifts null-related problems from runtime failures to compile-time feedback, helping developers detect issues earlier and build more reliable software.
Readonly (Final-by-Default)
JADEx also introduces optional readonly semantics through a final-by-default model.
In large Java codebases, accidental reassignment of variables or fields can lead to subtle bugs and make code harder to reason about. While Java provides the
finalkeyword, it must be manually applied everywhere, which often results in inconsistent usage.JADEx simplifies this by allowing developers to enable readonly mode with a single directive:
Once enabled:
Fields, local variables, and parameters become
finalby defaultJADEx automatically applies
finalwhere appropriateReassignment attempts are reported as compile-time errors
Example:
Since
countis generated asfinal, the reassignment results in a standard Java compile-time error.If mutability is intentionally required, developers can explicitly opt in using the
mutablemodifier:This approach encourages safer programming practices while keeping the code flexible when mutation is necessary.
When compiled, JADEx generates standard Java code with
finalmodifiers applied where appropriate, ensuring full compatibility with the existing Java ecosystem.Summary
JADEx introduces two complementary safety mechanisms:
Null-Safety
Non-null by default
Explicit nullable types
Safe access operators (
?.,?:)Compile-time detection of unsafe null usage
Readonly (Final-by-Default)
Final by default
Explicit opt-in for mutability
Automatic
finalgenerationPrevention of accidental reassignment
Together, these features strengthen Java’s type system while remaining fully compatible with existing Java libraries, tools, and workflows.
JADEx does not replace Java.
It simply adds a safety layer that makes Java safer while keeping full compatibility with the existing ecosystem.
All reactions