diff options
author | Aurelien Poscia <aurelien.poscia@sonarsource.com> | 2022-09-30 10:24:02 +0200 |
---|---|---|
committer | Philippe Perrin <philippe.perrin@sonarsource.com> | 2022-10-07 12:13:56 +0200 |
commit | 1a796086bedffa6c5f9fd7843a421eb1696b1c89 (patch) | |
tree | 30ce485c12dd6c1dac3c9a6457c8b16de6be94e4 | |
parent | 337c3b0cbe22bfb6a1ce111c65e62d496480f717 (diff) | |
download | sonarqube-1a796086bedffa6c5f9fd7843a421eb1696b1c89.tar.gz sonarqube-1a796086bedffa6c5f9fd7843a421eb1696b1c89.zip |
SONAR-17421 Do not fail if user provided timezone is unknown by the server
2 files changed, 15 insertions, 7 deletions
diff --git a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java index ef43b30c23a..f6c2773b806 100644 --- a/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java +++ b/server/sonar-webserver-es/src/main/java/org/sonar/server/issue/index/IssueQueryFactory.java @@ -45,6 +45,8 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.RuleType; import org.sonar.api.server.ServerSide; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; import org.sonar.core.util.stream.MoreCollectors; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -87,6 +89,8 @@ import static org.sonarqube.ws.client.issue.IssuesWsParameters.PARAM_SINCE_LEAK_ @ServerSide public class IssueQueryFactory { + private static final Logger LOGGER = Loggers.get(IssueQueryFactory.class); + public static final String UNKNOWN = "<UNKNOWN>"; public static final List<String> ISSUE_STATUSES = STATUSES.stream() .filter(s -> !s.equals(STATUS_TO_REVIEW)) @@ -167,7 +171,8 @@ public class IssueQueryFactory { try { return Optional.of(ZoneId.of(timeZone)); } catch (DateTimeException e) { - throw new IllegalArgumentException("TimeZone '" + timeZone + "' cannot be parsed as a valid zone ID"); + LOGGER.warn("TimeZone '" + timeZone + "' cannot be parsed as a valid zone ID"); + return Optional.empty(); } } diff --git a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java index a3dd520af59..772d49480d1 100644 --- a/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java +++ b/server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java @@ -30,6 +30,7 @@ import org.junit.Rule; import org.junit.Test; import org.sonar.api.resources.Qualifiers; import org.sonar.api.rule.RuleKey; +import org.sonar.api.utils.log.LogTester; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; @@ -67,6 +68,8 @@ public class IssueQueryFactoryTest { public UserSessionRule userSession = UserSessionRule.standalone(); @Rule public DbTester db = DbTester.create(); + @Rule + public LogTester logTester = new LogTester(); private final RuleDbTester ruleDbTester = new RuleDbTester(db); private final Clock clock = mock(Clock.class); @@ -330,13 +333,13 @@ public class IssueQueryFactoryTest { } @Test - public void fail_if_invalid_timezone() { - SearchRequest request = new SearchRequest() - .setTimeZone("Poitou-Charentes"); + public void timeZone_ifZoneFromQueryIsUnknown_fallbacksToClockZone() { + SearchRequest request = new SearchRequest().setTimeZone("Poitou-Charentes"); + when(clock.getZone()).thenReturn(ZoneId.systemDefault()); - assertThatThrownBy(() -> underTest.create(request)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("TimeZone 'Poitou-Charentes' cannot be parsed as a valid zone ID"); + IssueQuery issueQuery = underTest.create(request); + assertThat(issueQuery.timeZone()).isEqualTo(clock.getZone()); + assertThat(logTester.logs()).containsOnly("TimeZone 'Poitou-Charentes' cannot be parsed as a valid zone ID"); } @Test |