From 107d18bcc298a878cb7812e38661fdb4a65e86e7 Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Thu, 1 Nov 2018 13:20:50 +0100 Subject: [PATCH] SonarQube fixes --- .../business/EventBusiness.java | 24 +++++++------------ .../vaadinclubhelper/data/BaseEntity.java | 6 ++--- .../ui/components/EventGrid.java | 2 +- .../ui/components/PersonGrid.java | 4 ++-- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java index ecd8565..86e4141 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java @@ -50,15 +50,17 @@ public class EventBusiness { "Loading events from Google Calendar, forceRefresh={}", forceRefresh); - BufferedWriter out = null; - List list = new ArrayList<>(); - - try { - File f = new File("google_events.json"); - Files.delete(f.toPath()); - out = new BufferedWriter(new FileWriter(f)); + File f = new File("google_events.json"); + if (f.exists()) { + try { + Files.delete(f.toPath()); + } catch (IOException e) { + log.error("Error deleting file " + f.getAbsolutePath(), e); + } + } + try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) { String remoteHost = "localhost"; CalendarAdapter adapter = new CalendarAdapter(); @@ -80,14 +82,6 @@ public class EventBusiness { } catch (GeneralSecurityException | IOException | InterruptedException e) { log.error("Error loading events from google.", e); - } finally { - if (out != null) { - try { - out.close(); - } catch (IOException e) { - log.error("Error writing File", e); - } - } } return Collections.unmodifiableList(list); diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java index 571d47a..1e73df2 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/BaseEntity.java @@ -38,7 +38,7 @@ public abstract class BaseEntity { } public void setChanged(Date changed) { - this.changed = changed; + this.changed = new Date(changed.getTime()); } public Date getCreated() { @@ -46,7 +46,7 @@ public abstract class BaseEntity { } public void setCreated(Date created) { - this.created = created; + this.created = new Date(created.getTime()); } public Date getDeleted() { @@ -54,7 +54,7 @@ public abstract class BaseEntity { } public void setDeleted(Date deleted) { - this.deleted = deleted; + this.deleted = new Date(deleted.getTime()); } @Override diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java index 57c7353..01fa84c 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/EventGrid.java @@ -10,7 +10,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; public class EventGrid extends Grid { private static final long serialVersionUID = -5435770187868470290L; - private final DateTimeFormatter df = DateTimeFormatter + private transient final DateTimeFormatter df = DateTimeFormatter .ofLocalizedDate(FormatStyle.MEDIUM); public EventGrid() { diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java index f3e5e8c..7c68587 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java @@ -40,7 +40,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; public class PersonGrid extends CustomComponent { private static final long serialVersionUID = -8148097982839343673L; - private final Logger log = LoggerFactory.getLogger(getClass()); + private transient final Logger log = LoggerFactory.getLogger(getClass()); private final DateFormat birthFormat = DateFormat .getDateInstance(DateFormat.MEDIUM); @@ -52,7 +52,7 @@ public class PersonGrid extends CustomComponent { private final TextField textTitle; - private ClosedFunction closedFunction = null; + private transient ClosedFunction closedFunction = null; private ConfigurableFilterDataProvider> dataProvider; private Boolean selectedOnlyFilter; private Set groupMemberFilter;