Implement Java 5 Formatter support - #196
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #196 +/- ##
==========================================
- Coverage 90.77% 87.41% -3.37%
==========================================
Files 269 292 +23
Lines 33392 38301 +4909
==========================================
+ Hits 30312 33479 +3167
- Misses 3080 4822 +1742 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f05da094d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Pull request overview
This PR implements a Java 5–compatible formatting stack in RustJava, adding java.util.Formatter/Formattable plus the supporting Appendable/Closeable/Flushable/StringBuilder/Enum APIs, and wiring formatting entrypoints like String.format and PrintStream/PrintWriter format/printf. It also expands the runtime class registry and updates conformance/integration tests to validate Java 5 public API shapes and key formatting behaviors.
Changes:
- Add
java.util.Formatter+ formatting exceptions and a small integration fixture undertest_data/to validate end-to-end formatting/output behavior. - Introduce Java 5 IO/lang support types (
Appendable,Closeable,Flushable,AbstractStringBuilder,StringBuilder,Enum) and integrate them intoPrintStream,PrintWriter, andString. - Update/extend Rust tests to assert Java 5 descriptors, access flags, bridges, and selected behavioral contracts (autoboxing
valueOf, formatting IO behaviors, etc.).
Reviewed changes
Copilot reviewed 53 out of 57 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test_data/src/FormatterIntegration.java | New Java integration program exercising Formatter, Formattable, Appendable, and stream/writer formatting. |
| test_data/FormatterIntegration.txt | Expected output for the new formatter integration fixture. |
| java_runtime/tests/classes/java/util/mod.rs | Registers the new test_formatter module in util test suite. |
| java_runtime/tests/classes/java/util/test_formatter.rs | Adds API-shape and behavior tests for Formatter, formatting exceptions, Enum, and IO type bridges. |
| java_runtime/tests/classes/java/lang/mod.rs | Registers new test_string_builder module in lang test suite. |
| java_runtime/tests/classes/java/lang/test_string_builder.rs | New tests for Appendable and Java 5 StringBuilder hierarchy/bridges and UTF-16 behavior. |
| java_runtime/tests/classes/java/lang/test_string_buffer.rs | Updates expectations for StringBuffer hierarchy and method flags/descriptors. |
| java_runtime/tests/classes/java/lang/test_character.rs | Updates Character.valueOf(char) expectation for Java 5. |
| java_runtime/tests/classes/java/lang/test_boolean.rs | Updates Boolean.valueOf(boolean) expectation for Java 5 interning semantics. |
| java_runtime/tests/classes/java/io/test_print_writer.rs | Extends PrintWriter API surface checks (constructors + format/printf + append bridges + setError). |
| java_runtime/tests/classes/java/io/test_print_stream.rs | Extends PrintStream API surface checks and adds an autoFlush + format flush behavior assertion. |
| java_runtime/tests/classes/java/io/test_file_reader_writer.rs | Adds a regression test ensuring Formatter file constructors truncate before writing. |
| java_runtime/src/loader.rs | Registers new runtime class protos for formatter-related and supporting Java 5 classes. |
| java_runtime/src/classes/java/util.rs | Adds modules/exports for Formatter, exceptions, Formattable, and related types. |
| java_runtime/src/classes/java/util/formatter.rs | Core java.util.Formatter implementation and formatting engine. |
| java_runtime/src/classes/java/util/formattable.rs | Adds the java.util.Formattable interface proto. |
| java_runtime/src/classes/java/util/formattable_flags.rs | Adds java.util.FormattableFlags constants holder. |
| java_runtime/src/classes/java/util/formatter_closed_exception.rs | Adds FormatterClosedException. |
| java_runtime/src/classes/java/util/formatter_big_decimal_layout_form.rs | Adds Formatter$BigDecimalLayoutForm enum support for signature compatibility. |
| java_runtime/src/classes/java/util/illegal_format_exception.rs | Adds base IllegalFormatException. |
| java_runtime/src/classes/java/util/duplicate_format_flags_exception.rs | Adds DuplicateFormatFlagsException. |
| java_runtime/src/classes/java/util/illegal_format_flags_exception.rs | Adds IllegalFormatFlagsException. |
| java_runtime/src/classes/java/util/format_flags_conversion_mismatch_exception.rs | Adds FormatFlagsConversionMismatchException. |
| java_runtime/src/classes/java/util/illegal_format_conversion_exception.rs | Adds IllegalFormatConversionException. |
| java_runtime/src/classes/java/util/illegal_format_code_point_exception.rs | Adds IllegalFormatCodePointException. |
| java_runtime/src/classes/java/util/illegal_format_precision_exception.rs | Adds IllegalFormatPrecisionException. |
| java_runtime/src/classes/java/util/illegal_format_width_exception.rs | Adds IllegalFormatWidthException. |
| java_runtime/src/classes/java/util/missing_format_argument_exception.rs | Adds MissingFormatArgumentException. |
| java_runtime/src/classes/java/util/missing_format_width_exception.rs | Adds MissingFormatWidthException. |
| java_runtime/src/classes/java/util/unknown_format_conversion_exception.rs | Adds UnknownFormatConversionException. |
| java_runtime/src/classes/java/util/unknown_format_flags_exception.rs | Adds UnknownFormatFlagsException. |
| java_runtime/src/classes/java/lang.rs | Wires new Java 5 lang modules into the runtime (Appendable, AbstractStringBuilder, Enum, StringBuilder). |
| java_runtime/src/classes/java/lang/appendable.rs | Adds the java.lang.Appendable interface proto. |
| java_runtime/src/classes/java/lang/abstract_string_builder.rs | Adds AbstractStringBuilder implementation used by both StringBuffer and StringBuilder. |
| java_runtime/src/classes/java/lang/string_builder.rs | Adds StringBuilder implementation and bridge methods. |
| java_runtime/src/classes/java/lang/string_buffer.rs | Refactors StringBuffer to extend AbstractStringBuilder and adds Java 5 overloads/bridges. |
| java_runtime/src/classes/java/lang/enum.rs | Adds java.lang.Enum base implementation and Enum.valueOf. |
| java_runtime/src/classes/java/lang/string.rs | Adds String.format(...) overloads backed by Formatter. |
| java_runtime/src/classes/java/lang/boolean.rs | Adds Boolean.valueOf(boolean) returning interned constants. |
| java_runtime/src/classes/java/lang/byte.rs | Adds Byte.valueOf(byte). |
| java_runtime/src/classes/java/lang/character.rs | Adds Character.valueOf(char). |
| java_runtime/src/classes/java/lang/double.rs | Adds Double.valueOf(double). |
| java_runtime/src/classes/java/lang/float.rs | Adds Float.valueOf(float). |
| java_runtime/src/classes/java/lang/long.rs | Adds Long.valueOf(long). |
| java_runtime/src/classes/java/lang/short.rs | Adds Short.valueOf(short). |
| java_runtime/src/classes/java/io.rs | Exposes Closeable and Flushable in the java.io module exports. |
| java_runtime/src/classes/java/io/closeable.rs | Adds the java.io.Closeable interface proto. |
| java_runtime/src/classes/java/io/flushable.rs | Adds the java.io.Flushable interface proto. |
| java_runtime/src/classes/java/io/output_stream.rs | Updates OutputStream to implement Closeable/Flushable and fixes public/abstract method flags. |
| java_runtime/src/classes/java/io/writer.rs | Updates Writer to implement Appendable/Closeable/Flushable and adds append(...) methods + bridges. |
| java_runtime/src/classes/java/io/output_stream_writer.rs | Refactors encoding validation and reuse across new constructors/callers. |
| java_runtime/src/classes/java/io/print_stream.rs | Adds PrintStream.format/printf, Appendable bridges, and new constructors. |
| java_runtime/src/classes/java/io/print_writer.rs | Adds PrintWriter.format/printf, Appendable bridges, and new constructors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Formatter,Formattable, formatting exceptions, and common conversionsAppendable,Closeable,Flushable,StringBuilder, andEnumAPIsString.format,PrintStream.format/printf, andPrintWriter.format/printfCompatibility scope
This provides the practical Java 5 formatting subset used by typical applications. Date/time (
%t/%T), hexadecimal floating point (%a/%A), arbitrary-precision number formatting, and non-English locale localization remain out of scope.Validation
cargo test --workspace --quiet(524 passed, 1 pre-existing ignored)cargo clippy --workspace --all-targets -- -D warningscargo fmt --all -- --checkgit diff --check