Skip to content

Commit c856b76

Browse files
Edward McFarlanebretthoerner
authored andcommitted
Set default dsn when null or empty. (#546)
1 parent e74aff4 commit c856b76

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

sentry/src/main/java/io/sentry/dsn/Dsn.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sentry.dsn;
22

33
import io.sentry.config.Lookup;
4+
import io.sentry.util.Util;
45
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
67

@@ -79,12 +80,12 @@ public Dsn(URI dsn) throws InvalidDsnException {
7980
public static String dsnLookup() {
8081
String dsn = Lookup.lookup("dsn");
8182

82-
if (dsn == null) {
83+
if (Util.isNullOrEmpty(dsn)) {
8384
// check if the user accidentally set "dns" instead of "dsn"
8485
dsn = Lookup.lookup("dns");
8586
}
8687

87-
if (dsn == null) {
88+
if (Util.isNullOrEmpty(dsn)) {
8889
logger.warn("*** Couldn't find a suitable DSN, Sentry operations will do nothing!"
8990
+ " See documentation: https://docs.sentry.io/clients/java/ ***");
9091
dsn = DEFAULT_DSN;

sentry/src/test/java/io/sentry/dsn/DsnTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ public void testDsnLookupWithEnvironmentVariable(@Mocked("getenv") final System
116116
assertThat(Dsn.dsnLookup(), is(dsn));
117117
}
118118

119+
@Test
120+
public void testDsnLookupWithEmptyEnvironmentVariable(@Mocked("getenv") final System system) throws Exception {
121+
final String dsn = "";
122+
new NonStrictExpectations() {{
123+
System.getenv("SENTRY_DSN");
124+
result = dsn;
125+
}};
126+
127+
assertThat(Dsn.dsnLookup(), is(Dsn.DEFAULT_DSN));
128+
}
129+
119130
@Test(expectedExceptions = InvalidDsnException.class)
120131
public void testMissingSecretKeyInvalid() throws Exception {
121132
new Dsn("http://publicKey:@host/9");

0 commit comments

Comments
 (0)