- if (unformattedUrl.getProtocol() != null) {
- scheme = unformattedUrl.getProtocol();
- } else {
- scheme = "http";
- }
-
- final String authority = unformattedUrl.getAuthority();
- final String path = unformattedUrl.getPath();
- final String query = unformattedUrl.getQuery();
- final String fragment = unformattedUrl.getRef();
+ // The ternary operator (? :) makes sure that unformattedUrl.get() does not cause a null pointer exception.
+ final String scheme = unformattedUrl != null ? unformattedUrl.getProtocol() : null;
+ final String authority = unformattedUrl != null ? unformattedUrl.getAuthority() : null;
+ final String path = unformattedUrl != null ? unformattedUrl.getPath() : null;
+ final String query = unformattedUrl != null ? unformattedUrl.getQuery() : null;
+ final String fragment = unformattedUrl != null ? unformattedUrl.getRef() : null;