@@ -29,16 +29,16 @@ public final class MainEventProcessor implements EventProcessor {
2929 private final @ NotNull SentryOptions options ;
3030 private final @ NotNull SentryThreadFactory sentryThreadFactory ;
3131 private final @ NotNull SentryExceptionFactory sentryExceptionFactory ;
32- private final @ NotNull HostnameCache hostnameCache ;
32+ private final @ Nullable HostnameCache hostnameCache ;
3333
3434 MainEventProcessor (final @ NotNull SentryOptions options ) {
35- this (options , new HostnameCache ());
35+ this (options , options . isAttachServerName () ? new HostnameCache () : null );
3636 }
3737
3838 MainEventProcessor (
39- final @ NotNull SentryOptions options , final @ NotNull HostnameCache hostnameCache ) {
39+ final @ NotNull SentryOptions options , final @ Nullable HostnameCache hostnameCache ) {
4040 this .options = Objects .requireNonNull (options , "The SentryOptions is required." );
41- this .hostnameCache = Objects . requireNonNull ( hostnameCache , "The HostnameCache is required" ) ;
41+ this .hostnameCache = hostnameCache ;
4242
4343 final SentryStackTraceFactory sentryStackTraceFactory =
4444 new SentryStackTraceFactory (
@@ -148,7 +148,7 @@ private void processNonCachedEvent(final @NotNull SentryEvent event) {
148148 event .getUser ().setIpAddress (DEFAULT_IP_ADDRESS );
149149 }
150150 }
151- if (options .isAttachServerName () && event .getServerName () == null ) {
151+ if (options .isAttachServerName () && hostnameCache != null && event .getServerName () == null ) {
152152 event .setServerName (hostnameCache .getHostname ());
153153 }
154154 }
0 commit comments