Skip to content

Commit 5bb8a9b

Browse files
committed
[bugfix] Avoid IllegalArgumentException when formatting Instant retrieved via XML:DB API
1 parent d6fb7f9 commit 5bb8a9b

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

exist-core/src/main/java/org/exist/client/ClientFrame.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
import java.nio.file.Files;
7373
import java.nio.file.Path;
7474
import java.nio.file.Paths;
75-
import java.text.DateFormat;
76-
import java.time.format.DateTimeFormatter;
7775
import java.util.*;
7876
import java.util.List;
7977
import java.util.concurrent.*;
@@ -83,7 +81,7 @@
8381
import java.util.stream.Collectors;
8482

8583
import static java.nio.charset.StandardCharsets.UTF_8;
86-
import static java.time.ZoneOffset.UTC;
84+
import static org.exist.client.InteractiveClient.DATE_TIME_FORMATTER;
8785
import static org.exist.util.FileUtils.humanSize;
8886

8987
/**
@@ -1262,8 +1260,6 @@ private void setPermAction(final ActionEvent ev) throws PermissionDeniedExceptio
12621260
ModeDisplay mode = null;
12631261
SimpleACLPermissionAider acl = null;
12641262

1265-
final DateFormat dateTimeFormat = DateFormat.getDateTimeInstance();
1266-
12671263
final List<ResourceDescriptor> selected = new ArrayList<>();
12681264

12691265
boolean firstPerm = true;
@@ -1283,7 +1279,7 @@ private void setPermAction(final ActionEvent ev) throws PermissionDeniedExceptio
12831279

12841280
if (selectedRow.isCollection()) {
12851281
final Collection coll = collection.getChildCollection(thisName.toString());
1286-
thisCreated = dateTimeFormat.format(coll.getCreationTime());
1282+
thisCreated = DATE_TIME_FORMATTER.format(coll.getCreationTime());
12871283
thisModified = NON_APPLICABLE;
12881284
thisMimeType = COLLECTION_MIME_TYPE;
12891285
thisMessageDigestType = NON_APPLICABLE;
@@ -1292,8 +1288,8 @@ private void setPermAction(final ActionEvent ev) throws PermissionDeniedExceptio
12921288
thisPerm = service.getPermissions(coll);
12931289
} else {
12941290
final Resource res = collection.getResource(thisName.toString());
1295-
thisCreated = dateTimeFormat.format(res.getCreationTime());
1296-
thisModified = dateTimeFormat.format(res.getLastModificationTime());
1291+
thisCreated = DATE_TIME_FORMATTER.format(res.getCreationTime());
1292+
thisModified = DATE_TIME_FORMATTER.format(res.getLastModificationTime());
12971293
thisMimeType = ((EXistResource) res).getMimeType();
12981294
if (res instanceof EXistBinaryResource) {
12991295
final MessageDigest messageDigest = ((EXistBinaryResource) res).getContentDigest(DigestType.BLAKE_256);
@@ -1596,8 +1592,6 @@ static class ResourceTableModel extends AbstractTableModel {
15961592

15971593
private List<ResourceDescriptor> rows = null;
15981594

1599-
private DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(UTC);
1600-
16011595
public void setData(final List<ResourceDescriptor> rows) {
16021596
rows.sort(new ResourceComparator());
16031597
this.rows = rows;
@@ -1651,7 +1645,7 @@ public Object getValueAt(final int rowIndex, final int columnIndex) {
16511645
case 0:
16521646
return row.getName().toString();
16531647
case 1:
1654-
return dateFormat.format(row.getInstant());
1648+
return DATE_TIME_FORMATTER.format(row.getInstant());
16551649
case 2:
16561650
return row.getOwner();
16571651
case 3:

exist-core/src/main/java/org/exist/client/InteractiveClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.nio.file.Path;
3333
import java.nio.file.Paths;
3434
import java.time.Instant;
35+
import java.time.format.DateTimeFormatter;
3536
import java.util.*;
3637
import java.util.concurrent.atomic.AtomicReference;
3738
import java.util.function.BinaryOperator;
@@ -89,6 +90,7 @@
8990
import se.softhouse.jargo.ArgumentException;
9091

9192
import static java.nio.charset.StandardCharsets.UTF_8;
93+
import static java.time.ZoneOffset.UTC;
9294
import static javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION;
9395
import static org.exist.storage.serializers.EXistOutputKeys.OMIT_ORIGINAL_XML_DECLARATION;
9496
import static org.exist.storage.serializers.EXistOutputKeys.OUTPUT_DOCTYPE;
@@ -101,6 +103,8 @@
101103
*/
102104
public class InteractiveClient {
103105

106+
static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(UTC);
107+
104108
// ANSI colors for ls display
105109
// private final static String ANSI_BLUE = "\033[0;34m";
106110
private static final String ANSI_CYAN = "\033[0;36m";
@@ -397,7 +401,7 @@ protected void getResources() throws XMLDBException {
397401
if ("true".equals(properties.getProperty(PERMISSIONS))) {
398402
resources[i] = 'c' + perm.toString() + '\t' + getOwnerName(perm)
399403
+ '\t' + getGroupName(perm) + '\t'
400-
+ created.toString() + '\t'
404+
+ DATE_TIME_FORMATTER.format(created) + '\t'
401405
+ collectionName;
402406
} else {
403407
resources[i] = collectionName;
@@ -431,7 +435,7 @@ protected void getResources() throws XMLDBException {
431435
if ("true".equals(properties.getProperty(PERMISSIONS))) {
432436
resources[i] = '-' + perm.toString() + '\t' + getOwnerName(perm)
433437
+ '\t' + getGroupName(perm) + '\t'
434-
+ lastModificationTime.toString() + '\t'
438+
+ DATE_TIME_FORMATTER.format(lastModificationTime) + '\t'
435439
+ resourceId;
436440
} else {
437441
resources[i] = resourceId;

0 commit comments

Comments
 (0)