Skip to content

fix: avoid replacing dots in directory path when building output filename#481

Open
amitmishra11 wants to merge 1 commit into
ronmamo:masterfrom
amitmishra11:fix/java-code-serializer-path-with-dots
Open

fix: avoid replacing dots in directory path when building output filename#481
amitmishra11 wants to merge 1 commit into
ronmamo:masterfrom
amitmishra11:fix/java-code-serializer-path-with-dots

Conversation

@amitmishra11

Copy link
Copy Markdown

Summary

Fixes #478

JavaCodeSerializer.save() converts the name parameter to a file
path by calling name.replace('.', '/'). However, this replaces all
dots in the string, including dots that appear in directory path
components such as version numbers (e.g. reflections-0.9.16-r6).

As a result, when the output path contains dots in its directory
portion, the serialized .java file is written to the wrong location.

Example:

Input name:

/var/tmp/portage/dev-java/reflections-0.9.16-r6/work/reflections-0.9.16/src/test/java/org.reflections.MyTestModelStore

Before this fix, the output filename was:

/var/tmp/portage/dev-java/reflections-0/9/16-r6/work/reflections-0/9/16/src/test/java/org/reflections/MyTestModelStore.java

After this fix, the output filename is:

/var/tmp/portage/dev-java/reflections-0.9.16-r6/work/reflections-0.9.16/src/test/java/org/reflections/MyTestModelStore.java

Changes

  • Split the name parameter at the last / separator so that only
    the class name portion (which legitimately uses dots as package
    separators) undergoes the dot-to-slash substitution. The directory
    prefix is passed through unchanged.

Testing

The existing JavaCodeSerializerTest continues to pass. It exercises
the save-and-load round-trip and verifies that the generated store file
can be accessed via the expected class hierarchy.

…name

JavaCodeSerializer.save() was calling name.replace('.', '/') on the
entire name parameter, including any directory path prefix. This caused
directory components containing dots (e.g. version numbers like
reflections-0.9.16) to be treated as package separators, resulting in
serialized data being written to the wrong location.

The fix splits the name at the last '/' separator so that only the
class name portion (which legitimately uses dots as package separators)
is transformed. The directory prefix is kept unchanged.

Fixes ronmamo#478
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reflections saves serialized data in wrong directory if full path contains dots

1 participant