Skip to content

Commit

Permalink
errorprone::java util date (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb authored May 30, 2024
1 parent a104f3e commit 79cdf19
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 53 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.github.spullara.mustache.java</groupId>
<artifactId>compiler</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/command/MonitorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import picocli.CommandLine.Option;

import java.io.IOException;
import java.util.Date;
import java.time.Instant;
import java.util.concurrent.TimeUnit;

public abstract class MonitorCommand<T extends BaseResponseEntity> extends HttpCommand {
Expand Down Expand Up @@ -51,7 +51,7 @@ public void run(CommandLine c) {
setup();
try {
do {
LOG.info(new Date().toString());
LOG.info(Instant.now().toString());
collectEndpointData();
if (getMonitor()) {
TimeUnit.SECONDS.sleep(getSleepInterval());
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/emissary/core/BaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.rmi.Remote;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -160,7 +160,7 @@ public class BaseDataObject implements Serializable, Cloneable, Remote, IBaseDat
/**
* The timestamp for when the BaseDataObject was created. Used in data provenance tracking.
*/
protected Date creationTimestamp;
protected Instant creationTimestamp;

/**
* The extracted records, if any
Expand Down Expand Up @@ -252,7 +252,7 @@ public void checkForUnsafeDataChanges() {
*/
public BaseDataObject() {
this.theData = null;
setCreationTimestamp(new Date(System.currentTimeMillis()));
setCreationTimestamp(Instant.now());
}

/**
Expand All @@ -265,7 +265,7 @@ public BaseDataObject() {
public BaseDataObject(final byte[] newData, final String name) {
setData(newData);
setFilename(name);
setCreationTimestamp(new Date(System.currentTimeMillis()));
setCreationTimestamp(Instant.now());
}

/**
Expand Down Expand Up @@ -1373,7 +1373,7 @@ public IBaseDataObject clone() throws CloneNotSupportedException {
}

@Override
public Date getCreationTimestamp() {
public Instant getCreationTimestamp() {
return this.creationTimestamp;
}

Expand All @@ -1384,7 +1384,7 @@ public Date getCreationTimestamp() {
* @param creationTimestamp when this item was created
*/
@Override
public void setCreationTimestamp(final Date creationTimestamp) {
public void setCreationTimestamp(final Instant creationTimestamp) {
if (creationTimestamp == null) {
throw new IllegalArgumentException("Timestamp must not be null");
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/emissary/core/IBaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -814,17 +814,17 @@ enum MergePolicy {

/**
* Get the timestamp for when the object was created. This attribute will be used for data provenance.
*
*
* @return date - the timestamp the object was created
*/
Date getCreationTimestamp();
Instant getCreationTimestamp();

/**
* Set the timestamp for when the object was created
*
* @param creationTimestamp - the date the object was created
*/
void setCreationTimestamp(Date creationTimestamp);
void setCreationTimestamp(Instant creationTimestamp);

/**
* Get the List of extracted records
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/emissary/core/IBaseDataObjectHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -68,7 +67,7 @@ public static IBaseDataObject clone(final IBaseDataObject iBaseDataObject, final
bdo.addAlternateView(entry.getKey(), entry.getValue());
}
bdo.setPriority(iBaseDataObject.getPriority());
bdo.setCreationTimestamp((Date) iBaseDataObject.getCreationTimestamp().clone());
bdo.setCreationTimestamp(iBaseDataObject.getCreationTimestamp());
if (iBaseDataObject.getExtractedRecords() != null) {
bdo.setExtractedRecords(iBaseDataObject.getExtractedRecords());
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/emissary/directory/HeartbeatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Timer;
Expand Down Expand Up @@ -115,7 +114,7 @@ public HeartbeatManager(final String directoryKey, @Nullable final List<String>
}

// "smooth" execution every 30 seconds starting in 2 minutes
this.timer.schedule(new HeartbeatTask(), new Date(System.currentTimeMillis() + (this.initialDelaySeconds * 1000L)),
this.timer.schedule(new HeartbeatTask(), System.currentTimeMillis() + (this.initialDelaySeconds * 1000L),
(this.intervalSeconds * 1000L));
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/emissary/output/DropOffPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import emissary.util.ShortNameComparator;

import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -229,11 +230,13 @@ public List<IBaseDataObject> agentProcessHeavyDuty(final List<IBaseDataObject> p
if (outputCompletionPayloadSize && tld.hasContent()) {
logger.info(
"Finished DropOff for object {}, with external id: {}, with total processing time: {}ms, with filetype: {}, payload size: {} bytes",
tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld), (new Date().getTime() - tld.getCreationTimestamp().getTime()),
tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld),
Duration.between(Instant.now(), tld.getCreationTimestamp()).toMillis(),
tld.getFileType(), tld.getChannelSize());
} else {
logger.info("Finished DropOff for object {}, with external id: {}, with total processing time: {}ms, with filetype: {}",
tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld), (new Date().getTime() - tld.getCreationTimestamp().getTime()),
tld.getInternalId(), this.dropOffUtil.getBestId(tld, tld),
Duration.between(Instant.now(), tld.getCreationTimestamp()).toMillis(),
tld.getFileType());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/output/DropOffUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ protected void configure(@Nullable final Configurator configG) {
*/
public String generateBuildFileName() {
if (this.uuidInOutputFilenames) {
return (prefix + getDateOrdinalWithTime(new Date()) + UUID.randomUUID());
return (prefix + getDateOrdinalWithTime(Instant.now()) + UUID.randomUUID());
} else {
// Using some constants plus yyyyJJJhhmmss plus random digit, letter, digit
return (prefix + getDateOrdinalWithTime(new Date()) + prng.nextInt(10) + ALPHABET[prng.nextInt(ALPHABET.length)] + prng.nextInt(10));
return (prefix + getDateOrdinalWithTime(Instant.now()) + prng.nextInt(10) + ALPHABET[prng.nextInt(ALPHABET.length)] + prng.nextInt(10));
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/emissary/output/filter/JsonOutputFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.databind.ser.std.MapProperty;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.apache.commons.collections4.CollectionUtils;

import java.io.IOException;
import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -83,6 +84,7 @@ protected void initFilenameGenerator() {
protected void initJsonMapper() {
jsonMapper = new ObjectMapper();
jsonMapper.registerModule(new IbdoModule());
jsonMapper.registerModule(new JavaTimeModule());
jsonMapper.addMixIn(IBaseDataObject.class, emitPayload ? IbdoPayloadMixin.class : IbdoParameterMixin.class);
// the id in addFilter must match the annotation for JsonFilter
jsonMapper.setFilterProvider(new SimpleFilterProvider().addFilter("param_filter", new IbdoParameterFilter()));
Expand Down Expand Up @@ -250,7 +252,7 @@ abstract static class IbdoMixin {
abstract UUID getInternalId();

@JsonProperty("creationTimestamp")
abstract Date getCreationTimestamp();
abstract Instant getCreationTimestamp();

@JsonProperty("shortName")
abstract String shortName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;

@Deprecated
@SuppressWarnings("JavaUtilDate")
public class DateTimeFormatParserLegacy {

protected static final Logger logger = LoggerFactory.getLogger(DateTimeFormatParserLegacy.class);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/util/PayloadUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.time.Instant;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -116,7 +116,7 @@ public static String getPayloadDisplayString(final IBaseDataObject payload) {
final String fileName = payload.getFilename();
final String fileType = payload.getFileType();
final List<String> currentForms = payload.getAllCurrentForms();
final Date creationTimestamp = payload.getCreationTimestamp();
final Instant creationTimestamp = payload.getCreationTimestamp();

sb.append("\n").append("filename: ").append(fileName).append("\n").append(" creationTimestamp: ").append(creationTimestamp).append("\n")
.append(" currentForms: ").append(currentForms).append("\n").append(" filetype: ").append(fileType).append("\n")
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/emissary/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.zone.ZoneRulesException;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -242,8 +241,8 @@ public static String getISO8601DateFormatString() {
}


public static String getDateOrdinalWithTime(final Date d) {
return DATE_ORDINAL_WITH_TIME.format(d.toInstant().atZone(ZoneId.systemDefault()));
public static String getDateOrdinalWithTime(final Instant d) {
return DATE_ORDINAL_WITH_TIME.format(d.atZone(ZoneId.systemDefault()));
}

/** This class is not meant to be instantiated. */
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/emissary/util/WatcherThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.io.IOException;
import java.io.PrintStream;
import java.util.Date;
import java.time.Instant;
import javax.annotation.Nullable;

public class WatcherThread extends Thread {
Expand Down Expand Up @@ -76,7 +76,7 @@ public static void main(String[] args) throws IOException {

wt.setDelay(Integer.parseInt(args[0]));

System.out.println(name + " begins at " + new Date());
System.out.println(name + " begins at " + Instant.now());

Process proc = Runtime.getRuntime().exec(args[1]);

Expand All @@ -101,7 +101,7 @@ public static void main(String[] args) throws IOException {
Thread.currentThread().interrupt();
}

System.out.println(name + " ends at " + new Date());
System.out.println(name + " ends at " + Instant.now());


}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/emissary/core/BaseDataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void testDefaultConstructor_setDateTime() {
@Test
void testDefaultConstructor_getSetDateTime() {
// setup
final Date date = new Date(0);
final Instant date = Instant.now();

// test
this.b.setCreationTimestamp(date);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -214,7 +214,7 @@ void testDiffPriority() {

@Test
void testDiffCreationTimestamp() {
ibdo1.setCreationTimestamp(new Date(1234567890));
ibdo1.setCreationTimestamp(Instant.ofEpochSecond(1234567890));
final DiffCheckConfiguration options = DiffCheckConfiguration.configure().enableTimestamp().build();
verifyDiff(1, options);
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/emissary/core/IBaseDataObjectHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -165,8 +165,8 @@ void testClonePriority() {

@Test
void testCloneCreationTimestamp() {
ibdo1.setCreationTimestamp(new Date(1234567890));
verifyClone("getCreationTimestamp", ibdo1, IS_NOT_SAME, IS_EQUALS, EQUAL_WITHOUT_FULL_CLONE);
ibdo1.setCreationTimestamp(Instant.ofEpochSecond(1234567890));
verifyClone("getCreationTimestamp", ibdo1, DONT_CHECK, IS_EQUALS, EQUAL_WITHOUT_FULL_CLONE);
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/emissary/pickup/BreakableFilePickUpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.time.Instant;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -31,7 +31,7 @@ public void setBrokenDuringProcessing(boolean value) {
actBrokenDuringProcessing = value;
if (value == true) {
Timer t = new Timer("BreakableFilePickupClientMonitor", true);
t.schedule(new TimeToActBrokenTask(), new Date(System.currentTimeMillis()), 10L);
t.schedule(new TimeToActBrokenTask(), Instant.now().toEpochMilli(), 10L);

}
}
Expand Down
Loading

0 comments on commit 79cdf19

Please sign in to comment.