oshdb icon indicating copy to clipboard operation
oshdb copied to clipboard

change return type of metadata getter to Optional<String>

Open tyrasd opened this issue 2 years ago • 0 comments

Problem Description

The getter method for metadata properties in OSHDBJdbc currently returns null when a property is not present. This could lead to unexpected NullpointerExceptions when one does not know about this.

Expected Solution

If the method returns an Optional<String> it can/must be checked if a property was actually found by testing the return value accordingly.

Alternative Solutions

Just return an empty string ("") instead. This is not optimal, because one could not distinguish a situation where the actual value stored in the metadata table is an empty string. If a user doesn't care they can get this behaviour in the solution above by using returnedOptional.getOrDefault("").

Additional Context

see https://github.com/GIScience/oshdb/pull/419#discussion_r688581087

tyrasd avatar Aug 13 '21 15:08 tyrasd