{"action":"opened","issue":{"url":"https://api.github.com/repos/hvdwolf/jExifToolGUI/issues/29","repository_url":"https://api.github.com/repos/hvdwolf/jExifToolGUI","labels_url":"https://api.github.com/repos/hvdwolf/jExifToolGUI/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/hvdwolf/jExifToolGUI/issues/29/comments","events_url":"https://api.github.com/repos/hvdwolf/jExifToolGUI/issues/29/events","html_url":"https://github.com/hvdwolf/jExifToolGUI/issues/29","id":457177195,"node_id":"MDU6SXNzdWU0NTcxNzcxOTU=","number":29,"title":"Using optional instead of null if there is no value","user":{"login":"Swissbite","id":205621,"node_id":"MDQ6VXNlcjIwNTYyMQ==","avatar_url":"https://avatars3.githubusercontent.com/u/205621?v=4","gravatar_id":"","url":"https://api.github.com/users/Swissbite","html_url":"https://github.com/Swissbite","followers_url":"https://api.github.com/users/Swissbite/followers","following_url":"https://api.github.com/users/Swissbite/following{/other_user}","gists_url":"https://api.github.com/users/Swissbite/gists{/gist_id}","starred_url":"https://api.github.com/users/Swissbite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Swissbite/subscriptions","organizations_url":"https://api.github.com/users/Swissbite/orgs","repos_url":"https://api.github.com/users/Swissbite/repos","events_url":"https://api.github.com/users/Swissbite/events{/privacy}","received_events_url":"https://api.github.com/users/Swissbite/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-06-17T22:30:34Z","updated_at":"2019-06-17T22:30:34Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"As an example on the user settings: We are currently using null for no value. But it would be better and less error-prone if we use the Optional Type, introduced in Java 1.8.\r\n\r\nAs an example, the preferences facade interface would then look like:\r\n```java\r\n\r\npublic interface IPreferencesFacade {\r\n    enum PreferenceKey { /* ... */  }\r\n\r\n    boolean keyIsSet(PreferenceKey key);\r\n\r\n    Optional<String> getByKey(PreferenceKey key);\r\n    String getByKey(PreferenceKey key, String defaultValue);\r\n    boolean getByKey(PreferenceKey key, boolean defaultValue);\r\n    void storeByKey(PreferenceKey key, String value);\r\n    void storeByKey(PreferenceKey key, boolean value);\r\n\r\n    IPreferencesFacade defaultInstance = PreferencesFacade.thisFacade;\r\n}\r\n```\r\n\r\nThe benefit: If null, it is an error. If empty or present, the Optional can be asked:\r\n\r\n```java\r\n  @Override\r\n    public Optional<String> getByKey(PreferenceKey key) { return Optional.ofNullable(rootNode.get(key.key, null));\r\n    }\r\n\r\npublic boolean keyIsSet(PreferenceKey key) {\r\n        return getByKey(key).isPresent();\r\n    }\r\n```\r\nWith this approach, null pointer exceptions (NPE) are a real issue and not just a value which was not thought about that it may not be present."}}
{"actor":{"display_login":"Swissbite"}}