What happens if a paper with same topic gets published while writing undergraduate thesis?
As far as I know, in Germany, Bachelor's theses do not necessarily have to be "research", so novelty is not mandatory to graduate. Reproducing existing research would be fine, as long as it is noted and no plagiarism occurs (and the effort is commensurate: there will probably be implementation decisions to be made, etc.).

I have seen several bachelor theses on subjects such as "implementing PCIe communication" "writing a linux device driver" "build a softcore processor for the open-license parts of the ARMv4 instruction set" which have no novelty or research value but significant engineering effort. If the B.Sc. student has no ambitions for an academic career, this type of thing is perfectly appropriate and in line with their future professional work.