From cfd9912407a505d6005d70f89ffc01c2d19b7ab4 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Tue, 20 Aug 2013 12:26:24 +0200 Subject: [PATCH] Fix quality flaws --- .../core/sensors/GenerateAlertEvents.java | 9 ++------ .../core/timemachine/TendencyAnalyser.java | 6 +++--- .../ui/libraries/client/ProjectPanel.java | 2 +- .../java/org/sonar/batch/index/Bucket.java | 2 +- .../org/sonar/batch/index/DefaultIndex.java | 7 ++++--- .../profiling/PhasesSumUpTimeProfiler.java | 21 +++++-------------- .../core/measure/MeasureFilterFactory.java | 8 ++----- .../sonar/core/measure/MeasureFilterSort.java | 14 ++++++++----- .../org/sonar/maven/ExceptionHandling.java | 6 +++++- .../api/qualitymodel/Characteristic.java | 3 ++- .../api/utils/command/CommandExecutor.java | 8 ++----- .../sonar/server/configuration/Backup.java | 3 ++- .../server/exceptions/HttpException.java | 8 +++++-- .../server/platform/MasterServletFilter.java | 8 ++----- .../sonar/server/plugins/PluginDeployer.java | 9 ++++---- .../server/startup/JdbcDriverDeployer.java | 2 +- .../server/plugins/PluginDeployerTest.java | 1 - .../org/sonar/squid/recognizer/Detector.java | 2 +- .../wsclient/internal/EncodingUtils.java | 2 +- 19 files changed, 53 insertions(+), 68 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java index 4bdc0c13a06..3e048566bf6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/GenerateAlertEvents.java @@ -19,12 +19,7 @@ */ package org.sonar.plugins.core.sensors; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.batch.Event; -import org.sonar.api.batch.TimeMachine; -import org.sonar.api.batch.TimeMachineQuery; +import org.sonar.api.batch.*; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.Metric; @@ -71,7 +66,7 @@ public class GenerateAlertEvents implements Decorator { TimeMachineQuery query = new TimeMachineQuery(resource).setOnlyLastAnalysis(true).setMetrics(CoreMetrics.ALERT_STATUS); List measures = timeMachine.getMeasures(query); - Measure pastStatus = (measures != null && measures.size() == 1 ? measures.get(0) : null); + Measure pastStatus = measures != null && measures.size() == 1 ? measures.get(0) : null; String alertText = currentStatus.getAlertText(); Level alertLevel = currentStatus.getDataAsLevel(); String alertName = null; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java index 6923ec0fa94..92c964f7b61 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TendencyAnalyser.java @@ -68,9 +68,9 @@ public class TendencyAnalyser { if (nullValuesYList || nbrPoints == 1) { return null; } - double n0 = ((nbrPoints * sumXY) - (sumX * sumY)); - double d = ((nbrPoints * sumXPower2) - (sumX * sumX)); - double n1 = ((sumY * sumXPower2) - (sumX * sumXY)); + double n0 = (nbrPoints * sumXY) - (sumX * sumY); + double d = (nbrPoints * sumXPower2) - (sumX * sumX); + double n1 = (sumY * sumXPower2) - (sumX * sumXY); SlopeData result = new SlopeData(); diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java index 0dff6d7e40d..14d269610b5 100644 --- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java +++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/ui/libraries/client/ProjectPanel.java @@ -108,7 +108,7 @@ public class ProjectPanel extends FlowPanel { } public void filter() { - boolean visible = (tree.getItemCount() == 0 && !filters.hasKeyword()); + boolean visible = tree.getItemCount() == 0 && !filters.hasKeyword(); for (int index = 0; index < tree.getItemCount(); index++) { Library lib = (Library) tree.getItem(index); visible |= !lib.filter(filters.getKeywordFilter().getKeyword(), filters.isTestFiltered()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java index d44e9613e11..a7feab13006 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/Bucket.java @@ -71,7 +71,7 @@ public final class Bucket { } public List getChildren() { - return (children == null ? Collections.emptyList() : children); + return children == null ? Collections.emptyList() : children; } public Bucket getParent() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java index 40a2b99c773..308b9f02eb5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java @@ -331,9 +331,9 @@ public class DefaultIndex extends SonarIndex { } private static boolean isFiltered(Violation violation, ViolationQuery.SwitchMode mode) { - return (mode == ViolationQuery.SwitchMode.BOTH + return mode == ViolationQuery.SwitchMode.BOTH || (mode == ViolationQuery.SwitchMode.OFF && violation.isSwitchedOff()) - || (mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff())); + || (mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff()); } @Override @@ -535,7 +535,8 @@ public class DefaultIndex extends SonarIndex { boolean excluded = checkExclusion(resource, parentBucket); if (!excluded) { - Snapshot snapshot = persistence.saveResource(currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null)); + Resource parentSnapshot = parentBucket != null ? parentBucket.getResource() : null; + Snapshot snapshot = persistence.saveResource(currentProject, resource, parentSnapshot); if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) { graph.addComponent(resource, snapshot); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java index 9e35c1936d0..ed23f549868 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java @@ -25,16 +25,7 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.events.DecoratorExecutionHandler; -import org.sonar.api.batch.events.DecoratorsPhaseHandler; -import org.sonar.api.batch.events.InitializerExecutionHandler; -import org.sonar.api.batch.events.InitializersPhaseHandler; -import org.sonar.api.batch.events.MavenPhaseHandler; -import org.sonar.api.batch.events.PostJobExecutionHandler; -import org.sonar.api.batch.events.PostJobsPhaseHandler; -import org.sonar.api.batch.events.ProjectAnalysisHandler; -import org.sonar.api.batch.events.SensorExecutionHandler; -import org.sonar.api.batch.events.SensorsPhaseHandler; +import org.sonar.api.batch.events.*; import org.sonar.api.resources.Project; import org.sonar.api.utils.TimeUtils; import org.sonar.batch.events.BatchStepHandler; @@ -51,7 +42,7 @@ import static org.sonar.batch.profiling.AbstractTimeProfiling.sortByDescendingTo import static org.sonar.batch.profiling.AbstractTimeProfiling.truncate; public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, DecoratorExecutionHandler, PostJobExecutionHandler, DecoratorsPhaseHandler, - SensorsPhaseHandler, PostJobsPhaseHandler, MavenPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler { + SensorsPhaseHandler, PostJobsPhaseHandler, MavenPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler { static final Logger LOG = LoggerFactory.getLogger(PhasesSumUpTimeProfiler.class); private static final int TEXT_RIGHT_PAD = 60; @@ -166,7 +157,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx } else { for (Decorator decorator : decoratorsProfiler.getDurations().keySet()) { currentModuleProfiling.getProfilingPerPhase(Phases.Phase.DECORATOR) - .getProfilingPerItem(decorator).setTotalTime(decoratorsProfiler.getDurations().get(decorator)); + .getProfilingPerItem(decorator).setTotalTime(decoratorsProfiler.getDurations().get(decorator)); } currentModuleProfiling.getProfilingPerPhase(Phases.Phase.DECORATOR).stop(); } @@ -202,8 +193,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx public void onInitializersPhase(InitializersPhaseEvent event) { if (event.isStart()) { currentModuleProfiling.addPhaseProfiling(Phases.Phase.INIT); - } - else { + } else { currentModuleProfiling.getProfilingPerPhase(Phases.Phase.INIT).stop(); } } @@ -222,8 +212,7 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx public void onBatchStep(BatchStepEvent event) { if (event.isStart()) { currentModuleProfiling.addBatchStepProfiling(event.stepName()); - } - else { + } else { currentModuleProfiling.getProfilingPerBatchStep(event.stepName()).stop(); } } diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java index 22f8fdf6a67..1431b303019 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterFactory.java @@ -32,11 +32,7 @@ import org.sonar.api.utils.DateUtils; import javax.annotation.Nullable; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; public class MeasureFilterFactory implements ServerComponent { @@ -55,7 +51,7 @@ public class MeasureFilterFactory implements ServerComponent { filter.setResourceScopes(toList(properties.get("scopes"))); filter.setResourceQualifiers(toList(properties.get("qualifiers"))); filter.setResourceLanguages(toList(properties.get("languages"))); - MeasureFilterCondition condition = alertToCondition((toList(properties.get("alertLevels")))); + MeasureFilterCondition condition = alertToCondition(toList(properties.get("alertLevels"))); if (condition != null) { filter.addCondition(condition); } diff --git a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java index 4af58151c38..b3ee0d6f1ae 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/MeasureFilterSort.java @@ -116,15 +116,19 @@ class MeasureFilterSort { column = "p.created_at"; break; case METRIC: - if (metric.isNumericType()) { - column = (period != null ? "pmsort.variation_value_" + period : "pmsort.value"); - } else { - column = "pmsort.text_value"; - } + column = getMetricColumn(); break; default: throw new IllegalArgumentException("Unsupported sorting: " + field); } return column; } + + private String getMetricColumn(){ + if (metric.isNumericType()) { + return period != null ? "pmsort.variation_value_" + period : "pmsort.value"; + } else { + return "pmsort.text_value"; + } + } } diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/ExceptionHandling.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/ExceptionHandling.java index 2fcd44e55e2..2baf46278d7 100644 --- a/sonar-maven-plugin/src/main/java/org/sonar/maven/ExceptionHandling.java +++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/ExceptionHandling.java @@ -24,9 +24,13 @@ import org.apache.maven.plugin.logging.Log; class ExceptionHandling { + private ExceptionHandling(){ + // Hide public constructor + } + static RuntimeException handle(Exception e, Log log) throws MojoExecutionException { Throwable source = e; - if (e.getClass().getName().equals("org.sonar.runner.impl.RunnerException") && e.getCause() != null) { + if ("org.sonar.runner.impl.RunnerException".equals(e.getClass().getName()) && e.getCause() != null) { source = e.getCause(); } log.error(source.getMessage()); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java index 33940a06ff2..17b518de8f9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/qualitymodel/Characteristic.java @@ -28,6 +28,7 @@ import org.hibernate.annotations.SortType; import org.sonar.api.rules.Rule; import javax.persistence.*; + import java.util.Collections; import java.util.List; @@ -299,7 +300,7 @@ public final class Characteristic implements Comparable { public Double getPropertyValue(String key, Double defaultValue) { CharacteristicProperty property = getProperty(key); - Double value = (property != null ? property.getValue() : null); + Double value = property != null ? property.getValue() : null; return value == null ? defaultValue : value; } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java index 15227f0deb7..55878682ff6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java @@ -27,12 +27,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import java.util.concurrent.*; /** * Synchronously execute a native command line. It's much more limited than the Apache Commons Exec library. @@ -79,6 +74,7 @@ public class CommandExecutor { final Process finalProcess = process; executorService = Executors.newSingleThreadExecutor(); Future ft = executorService.submit(new Callable() { + @Override public Integer call() throws Exception { return finalProcess.waitFor(); } diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java index 0b3f3e2f9a2..0c80cc0de4e 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/Backup.java @@ -34,6 +34,7 @@ import org.sonar.core.persistence.DatabaseVersion; import org.sonar.server.platform.PersistentSettings; import javax.annotation.Nullable; + import java.io.IOException; import java.io.InputStream; import java.io.Writer; @@ -137,7 +138,7 @@ public class Backup { return (SonarConfig) xStream.fromXML(inputStream); } catch (IOException e) { - throw new RuntimeException("Can't read xml", e); + throw new IllegalStateException("Can't read xml", e); } } diff --git a/sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java b/sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java index b3d8d2f9875..7a8cd4176a8 100644 --- a/sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java +++ b/sonar-server/src/main/java/org/sonar/server/exceptions/HttpException.java @@ -30,16 +30,20 @@ import static com.google.common.collect.Lists.newArrayList; public class HttpException extends RuntimeException { private final int httpCode; - private String l10nKey; - private Collection l10nParams; + private final String l10nKey; + private final Collection l10nParams; public HttpException(int httpCode) { this.httpCode = httpCode; + this.l10nKey = null; + this.l10nParams = null; } public HttpException(int httpCode, String message) { super(message); this.httpCode = httpCode; + this.l10nKey = null; + this.l10nParams = null; } public HttpException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/MasterServletFilter.java b/sonar-server/src/main/java/org/sonar/server/platform/MasterServletFilter.java index 0e8ec2db19d..e7742c3400b 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/MasterServletFilter.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/MasterServletFilter.java @@ -25,12 +25,7 @@ import com.google.common.collect.Lists; import org.slf4j.LoggerFactory; import org.sonar.api.web.ServletFilter; -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; +import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; @@ -117,6 +112,7 @@ public class MasterServletFilter implements Filter { this.chain = chain; } + @Override public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { if (iterator == null) { iterator = filters.iterator(); diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java index 7a0f57f3d21..d183e9a0a8f 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java @@ -30,7 +30,6 @@ import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; import org.sonar.api.platform.PluginMetadata; import org.sonar.api.platform.Server; -import org.sonar.api.utils.SonarException; import org.sonar.api.utils.TimeProfiler; import org.sonar.core.plugins.DefaultPluginMetadata; import org.sonar.core.plugins.PluginInstaller; @@ -83,7 +82,7 @@ public class PluginDeployer implements ServerComponent { FileUtils.deleteDirectory(trashDir); } } catch (IOException e) { - throw new SonarException("Fail to clean the plugin trash directory: " + trashDir, e); + throw new IllegalStateException("Fail to clean the plugin trash directory: " + trashDir, e); } } @@ -161,7 +160,7 @@ public class PluginDeployer implements ServerComponent { File masterFile = new File(fileSystem.getUserPluginsDir(), metadata.getFile().getName()); FileUtils.moveFileToDirectory(masterFile, fileSystem.getRemovedPluginsDir(), true); } catch (IOException e) { - throw new SonarException("Fail to uninstall plugin: " + pluginKey, e); + throw new IllegalStateException("Fail to uninstall plugin: " + pluginKey, e); } } } @@ -184,7 +183,7 @@ public class PluginDeployer implements ServerComponent { try { FileUtils.moveFileToDirectory(file, fileSystem.getUserPluginsDir(), false); } catch (IOException e) { - throw new SonarException("Fail to cancel plugin uninstalls", e); + throw new IllegalStateException("Fail to cancel plugin uninstalls", e); } } } @@ -215,7 +214,7 @@ public class PluginDeployer implements ServerComponent { installer.install(plugin, pluginDeployDir); } catch (IOException e) { - throw new RuntimeException("Fail to deploy the plugin " + plugin, e); + throw new IllegalStateException("Fail to deploy the plugin " + plugin, e); } } diff --git a/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java b/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java index bf40292c628..9529bf6d762 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/JdbcDriverDeployer.java @@ -42,7 +42,7 @@ public class JdbcDriverDeployer { FileUtils.copyFile(driver, deployedDriver); } catch (IOException e) { - throw new RuntimeException("Can not copy the JDBC driver from " + driver + " to " + deployedDriver, e); + throw new IllegalStateException("Can not copy the JDBC driver from " + driver + " to " + deployedDriver, e); } } File deployedDriverIndex = fileSystem.getDeployedJdbcDriverIndex(); diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java index 956d0409c7b..7d5ededcba4 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java @@ -48,7 +48,6 @@ public class PluginDeployerTest { private File deployDir; private PluginDeployer deployer; private Server server = mock(Server.class); - private UpdateCenterMatrixFactory updateCenterMatrixFactory; @Before public void start() { diff --git a/sonar-squid/src/main/java/org/sonar/squid/recognizer/Detector.java b/sonar-squid/src/main/java/org/sonar/squid/recognizer/Detector.java index 867ff9658ad..956d6fc1451 100644 --- a/sonar-squid/src/main/java/org/sonar/squid/recognizer/Detector.java +++ b/sonar-squid/src/main/java/org/sonar/squid/recognizer/Detector.java @@ -22,7 +22,7 @@ package org.sonar.squid.recognizer; public abstract class Detector { - public final double probability; + private final double probability; public Detector(double probability) { if (probability < 0 || probability > 1) { diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/EncodingUtils.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/EncodingUtils.java index 99be0b4af2f..51354057bb9 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/EncodingUtils.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/internal/EncodingUtils.java @@ -64,7 +64,7 @@ public class EncodingUtils { } public static String toQueryParam(Date d, boolean includeTime) { - String format = (includeTime ? DATETIME_FORMAT : DATE_FORMAT); + String format = includeTime ? DATETIME_FORMAT : DATE_FORMAT; SimpleDateFormat dateFormat = new SimpleDateFormat(format); return dateFormat.format(d); } -- 2.39.5