You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
The CodeWriter class currently includes content validation here that prevents overwriting files with different content. This appears to be an anti-pattern that goes against the fundamental nature of code generation.
Why this is problematic
Code generation, by definition, should be:
Deterministic - Same input should produce same output
Repeatable - Should be able to run multiple times without side effects
Idempotent - The final state should be determined by the input model, not the previous state
The current content validation
Assumes generated files should never change without manual cleanup
Creates unnecessary coupling between previous and new generation runs
Forces developers to manually clean directories between generations
Adds complexity to build processes that should be straightforward
Proposed Change
Remove the content validation entirely. Code generation should simply:
Generate the new files
Write them to the specified location
Overwrite any existing files
This would
Simplify the code
Remove an unnecessary validation
Make the generation process more reliable
Follow standard code generation patterns
The original intent might have been to catch configuration errors, but this should be handled through proper input validation and clear error messages about the input model, not by validating output files against their previous state.
Regression Issue
Select this option if this issue appears to be a regression.
Expected Behavior
When running code generation:
The generator should process the Smithy model and generate the corresponding Java code
Any existing files in the output directory should be overwritten with the newly generated content
The process should complete successfully regardless of what files existed before
The final state of the generated code should depend only on the current input model, not on previous generations
Current Behavior
When running code generation, if a file already exists in the output directory, the generator:
Reads the existing file
Compares its content with the newly generated content
Throws an IllegalStateException if they don't match:
java.lang.RuntimeException: Failed to generate code. Exception message: java.lang.IllegalStateException: Attempted to clobber existing file (...) with a new file that has different content. This may indicate forgetting to clean up old generated files before running the generator?
This forces users to manually delete generated files between runs, complicating build processes and development workflows.
Reproduction Steps
Given some codegen setup and a clean build environment
Run the codegen task
Change the input mode
Run the codegen task again
On step 3 the codegen task fails with an IllegalStateException
Possible Solution
Remove the content validation entirely. Or at least make it configurable and default to on if there are backwards compatibility concerns (but it is quite the smell if a project relies on this check).
Additional Information/Context
No response
AWS Java SDK version used
2.30.32
JDK version used
21
Operating System and version
MacOS 15
The text was updated successfully, but these errors were encountered:
Describe the bug
Description
The
CodeWriter
class currently includes content validation here that prevents overwriting files with different content. This appears to be an anti-pattern that goes against the fundamental nature of code generation.Why this is problematic
Code generation, by definition, should be:
The current content validation
Proposed Change
Remove the content validation entirely. Code generation should simply:
This would
The original intent might have been to catch configuration errors, but this should be handled through proper input validation and clear error messages about the input model, not by validating output files against their previous state.
Regression Issue
Expected Behavior
When running code generation:
Current Behavior
When running code generation, if a file already exists in the output directory, the generator:
This forces users to manually delete generated files between runs, complicating build processes and development workflows.
Reproduction Steps
Given some codegen setup and a clean build environment
On step 3 the codegen task fails with an
IllegalStateException
Possible Solution
Remove the content validation entirely. Or at least make it configurable and default to on if there are backwards compatibility concerns (but it is quite the smell if a project relies on this check).
Additional Information/Context
No response
AWS Java SDK version used
2.30.32
JDK version used
21
Operating System and version
MacOS 15
The text was updated successfully, but these errors were encountered: