reflections icon indicating copy to clipboard operation
reflections copied to clipboard

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

Open NHOrus opened this issue 10 months ago • 2 comments

https://github.com/ronmamo/reflections/blob/f5514b125c4f4b58e92beb0979a40ddce48d5be1/src/main/java/org/reflections/serializers/JavaCodeSerializer.java#L73

so, e.g. if it tries to save reflection data of org.reflections.MyTestModelStore to
/var/tmp/portage/dev-java/reflections-0.9.16-r6/work/reflections-0.9.16/src/test/java/org/reflections/MyTestModelStore.java
it would instead save it to
/var/tmp/portage/dev-java/reflections-0/9/12-r6/work/reflections-0/9/12/src/test/java/org/reflections/MyTestModelStore.java
which is incorrect.

Found in Gentoo: https://bugs.gentoo.org/949232

NHOrus avatar Feb 20 '25 19:02 NHOrus

Right solution would be something like:

File temporaryfile = File(name)
String temppath = temporaryfile.getParent()
String tempname = temporaryfile.getName().replace('.', File.separator).concat(".java")
String filename = temppath + File.separator + tempname

But I don't know java well

NHOrus avatar Feb 20 '25 19:02 NHOrus

Elaborating: That line replaces all the dots in the path string with slashes, because it expects that only classname at the end of the name contains dots. Assumption that is proven incorrect when given absolute path with dots in it.

NHOrus avatar Feb 20 '25 19:02 NHOrus