This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 7d818ee3f9 some changes related to java 17 (#1131)
7d818ee3f9 is described below
commit 7d818ee3f99a05ec8fb800504355be5a4e4651ff
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Jun 11 13:03:17 2026 +0100
some changes related to java 17 (#1131)
---
README.md | 2 +-
.../java/org/apache/poi/stress/TestAllFiles.java | 11 ----
.../poi/poifs/crypt/dsig/TestSignatureInfo.java | 9 ----
.../main/java/org/apache/poi/hdgf/HDGFDiagram.java | 18 +++----
.../java/org/apache/poi/hdgf/dev/VSDDumper.java | 8 +--
.../poi/hdgf/extractor/VisioTextExtractor.java | 6 +--
.../poi/hdgf/streams/PointerContainingStream.java | 7 +--
.../apache/poi/hemf/record/emf/HemfComment.java | 4 +-
.../org/apache/poi/hemf/record/emf/HemfRecord.java | 4 +-
.../poi/hemf/record/emfplus/HemfPlusObject.java | 10 ++--
.../org/apache/poi/hemf/usermodel/HemfPicture.java | 4 +-
.../main/java/org/apache/poi/hmef/Attachment.java | 3 +-
.../main/java/org/apache/poi/hmef/HMEFMessage.java | 3 +-
.../org/apache/poi/hslf/dev/TextStyleListing.java | 11 ++--
.../apache/poi/hslf/record/CurrentUserAtom.java | 58 +++++++++++-----------
.../org/apache/poi/hslf/record/PPDrawingGroup.java | 6 +--
.../poi/hslf/usermodel/HSLFSlideShowImpl.java | 24 ++++-----
.../poi/hslf/usermodel/HSLFTextParagraph.java | 16 +++---
.../org/apache/poi/hslf/util/LocaleDateFormat.java | 14 ++----
.../main/java/org/apache/poi/hsmf/MAPIMessage.java | 16 +++---
20 files changed, 102 insertions(+), 132 deletions(-)
diff --git a/README.md b/README.md
index 3b1d263161..c67dcb7181 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ A good resource for finding the published jars and forming
build tool dependency
# Contributing
-* Download and install git, Java JDK 11+, and Apache Ant 1.8+ or Gradle
+* Download and install git, Java JDK 17+, and Apache Ant 1.8+ or Gradle
* Check out the code from git
diff --git
a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
index 00589d5133..573bda9b9a 100644
--- a/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
+++ b/poi-integration/src/test/java/org/apache/poi/stress/TestAllFiles.java
@@ -37,7 +37,6 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.util.IOUtils;
import org.apache.tools.ant.DirectoryScanner;
-import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -239,12 +238,6 @@ public class TestAllFiles {
try {
Thread.currentThread().setName("Handle - " + file + " - " +
handler);
- // Some of the tests hang in JDK 8 due to Graphics-Rendering
issues in JDK itself,
- // therefore we do not run some tests here
- Assumptions.assumeFalse(isJava8() && (
- file.endsWith("23884_defense_FINAL_OOimport_edit.ppt")
- ), "Some files hang in JDK graphics rendering on Java 8 due to a
JDK bug");
-
System.out.println("Running handleFiles on "+file);
FileHandler fileHandler = handler.getHandler();
assertNotNull(fileHandler, "Did not find a handler for file " +
file);
@@ -353,10 +346,6 @@ public class TestAllFiles {
return msg;
}
- private static boolean isJava8() {
- return System.getProperty("java.version").startsWith("1.8");
- }
-
private static String[] concat(String[] a, String[] b) {
String[] result = new String[a.length + b.length];
System.arraycopy(a, 0, result, 0, a.length);
diff --git
a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
index 539fffa58c..c0e42866b9 100644
---
a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
+++
b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java
@@ -89,7 +89,6 @@ import
org.apache.poi.poifs.crypt.dsig.services.RevocationDataService;
import org.apache.poi.poifs.crypt.dsig.services.TimeStampService;
import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator;
import org.apache.poi.ss.usermodel.WorkbookFactory;
-import org.apache.poi.util.ConditionalExecution.DisabledOnJreEx;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.StringUtil;
@@ -353,7 +352,6 @@ class TestSignatureInfo {
}
@Test
- @DisabledOnJreEx("1.8.0_292")
void testSignSpreadsheet() throws Exception {
String testFile = "hello-world-unsigned.xlsx";
try (OPCPackage pkg =
OPCPackage.open(copy(testdata.getFile(testFile)), PackageAccess.READ_WRITE)) {
@@ -372,7 +370,6 @@ class TestSignatureInfo {
}
@Test
- @DisabledOnJreEx("1.8.0_292")
void testManipulation() throws Exception {
// sign & validate
String testFile = "hello-world-unsigned.xlsx";
@@ -400,7 +397,6 @@ class TestSignatureInfo {
}
@Test
- @DisabledOnJreEx("1.8.0_292")
void testSignSpreadsheetWithSignatureInfo() throws Exception {
String testFile = "hello-world-unsigned.xlsx";
DummyKeystore ks = new DummyKeystore(STORE_PASS);
@@ -427,7 +423,6 @@ class TestSignatureInfo {
}
@Test
- @DisabledOnJreEx("1.8.0_292")
void testSignEnvelopingDocument() throws Exception {
String testFile = "hello-world-unsigned.xlsx";
File sigCopy = testdata.getFile(testFile);
@@ -662,7 +657,6 @@ class TestSignatureInfo {
}
@Test
- @DisabledOnJreEx("1.8.0_292")
void testNonSha1() throws Exception {
String testFile = "hello-world-unsigned.xlsx";
DummyKeystore ks = new DummyKeystore(STORE_PASS);
@@ -693,7 +687,6 @@ class TestSignatureInfo {
// Test signing of external references / hyperlinks
@Test
- @DisabledOnJreEx("1.8.0_292")
void bug65214() throws Exception {
DummyKeystore ks = new DummyKeystore(STORE_PASS);
KeyCertPair certPair = ks.createDummyKey();
@@ -733,7 +726,6 @@ class TestSignatureInfo {
}
@Test
- @DisabledOnJreEx("1.8.0_292")
void bug58630() throws Exception {
DummyKeystore ks = new DummyKeystore(STORE_PASS);
KeyCertPair certPair = ks.createDummyKey();
@@ -968,7 +960,6 @@ class TestSignatureInfo {
@Test
- @DisabledOnJreEx("1.8.0_292")
@Tag("scratchpad.ignore")
void testSignatureImage() throws Exception {
DummyKeystore ks = new DummyKeystore(STORE_PASS);
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFDiagram.java
b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFDiagram.java
index 78f71aa7e9..0959f977e3 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFDiagram.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/HDGFDiagram.java
@@ -83,13 +83,14 @@ public final class HDGFDiagram extends POIReadOnlyDocument {
// Now grab the trailer
Stream stream = Stream.createStream(trailerPointer, _docstream,
chunkFactory, ptrFactory);
- if (!(stream instanceof TrailerStream)) {
+ if (stream instanceof TrailerStream ts) {
+ trailer = ts;
+
+ // Finally, find all our streams
+ trailer.findChildren(_docstream);
+ } else {
throw new IllegalStateException("Stream is not a TrailerStream: "
+ stream);
}
- trailer = (TrailerStream)stream;
-
- // Finally, find all our streams
- trailer.findChildren(_docstream);
}
/**
@@ -133,9 +134,7 @@ public final class HDGFDiagram extends POIReadOnlyDocument {
System.err.println("\tCompressed is " +
ptr.destinationCompressed());
System.err.println("\tStream is " + stream.getClass());
- if(stream instanceof PointerContainingStream) {
- PointerContainingStream pcs = (PointerContainingStream)stream;
-
+ if(stream instanceof PointerContainingStream pcs) {
if(pcs.getPointedToStreams() != null &&
pcs.getPointedToStreams().length > 0) {
System.err.println("\tContains " +
pcs.getPointedToStreams().length + " other pointers/streams");
for(int j=0; j<pcs.getPointedToStreams().length; j++) {
@@ -147,9 +146,8 @@ public final class HDGFDiagram extends POIReadOnlyDocument {
}
}
- if(stream instanceof StringsStream) {
+ if(stream instanceof StringsStream ss) {
System.err.println("\t\t**strings**");
- StringsStream ss = (StringsStream)stream;
System.err.println("\t\t" + ss._getContentsLength());
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/dev/VSDDumper.java
b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/dev/VSDDumper.java
index ddbd4801d9..2196cd47ae 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/dev/VSDDumper.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/dev/VSDDumper.java
@@ -82,16 +82,16 @@ public final class VSDDumper {
String ds = (db.length >= 8) ? Arrays.toString(db) : "[]";
dumpVal("First few bytes are", ds, indent+1);
- if (stream instanceof PointerContainingStream) {
- Stream[] streams = ((PointerContainingStream)
stream).getPointedToStreams();
+ if (stream instanceof PointerContainingStream pcs) {
+ Stream[] streams = pcs.getPointedToStreams();
dumpVal("Nbr of children", streams.length, indent+1);
for(Stream s : streams) {
dumpStream(s, indent+1);
}
}
- if(stream instanceof ChunkStream) {
- Chunk[] chunks = ((ChunkStream) stream).getChunks();
+ if(stream instanceof ChunkStream cs) {
+ Chunk[] chunks = cs.getChunks();
dumpVal("Nbr of chunks", chunks.length, indent+1);
for(Chunk chunk : chunks) {
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
index 30eab3e843..afcf579bef 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
@@ -70,16 +70,14 @@ public final class VisioTextExtractor implements
POIOLE2TextExtractor {
return text.toArray(new String[0]);
}
private void findText(Stream stream, List<String> text) {
- if(stream instanceof PointerContainingStream) {
- PointerContainingStream ps = (PointerContainingStream)stream;
+ if(stream instanceof PointerContainingStream ps) {
if (ps.getPointedToStreams() != null) {
for (final Stream substream : ps.getPointedToStreams()) {
findText(substream, text);
}
}
}
- if(stream instanceof ChunkStream) {
- ChunkStream cs = (ChunkStream)stream;
+ if(stream instanceof ChunkStream cs) {
for(final Chunk chunk : cs.getChunks()) {
if(chunk != null &&
chunk.getName() != null &&
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/PointerContainingStream.java
b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/PointerContainingStream.java
index 387cb8580d..a11533186e 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/PointerContainingStream.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/streams/PointerContainingStream.java
@@ -79,15 +79,12 @@ public class PointerContainingStream extends Stream { //
TODO - instantiable sup
childStreams[i] = Stream.createStream(ptr, documentData,
chunkFactory, pointerFactory);
// Process chunk streams into their chunks
- if(childStreams[i] instanceof ChunkStream) {
- ChunkStream child = (ChunkStream)childStreams[i];
+ if(childStreams[i] instanceof ChunkStream child) {
child.findChunks();
}
// Recurse into pointer containing streams
- if(childStreams[i] instanceof PointerContainingStream) {
- PointerContainingStream child =
- (PointerContainingStream)childStreams[i];
+ if(childStreams[i] instanceof PointerContainingStream child) {
child.findChildren(documentData, nesting + 1);
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfComment.java
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfComment.java
index 29e49bb41f..62a70a6fc3 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfComment.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfComment.java
@@ -183,8 +183,8 @@ public class HemfComment {
@Override
public void setCharsetProvider(Supplier<Charset> provider) {
- if (data instanceof HwmfCharsetAware) {
- ((HwmfCharsetAware)data).setCharsetProvider(provider);
+ if (data instanceof HwmfCharsetAware charsetAware) {
+ charsetAware.setCharsetProvider(provider);
}
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfRecord.java
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfRecord.java
index 613b1f028e..d59cb8cd3a 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfRecord.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfRecord.java
@@ -52,8 +52,8 @@ public interface HemfRecord extends GenericRecord {
* @param ctx the drawing context
*/
default void draw(HemfGraphics ctx) {
- if (this instanceof HwmfRecord) {
- ((HwmfRecord) this).draw(ctx);
+ if (this instanceof HwmfRecord hwmfRecord) {
+ hwmfRecord.draw(ctx);
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
index 4db5dedb92..e21bb226ff 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusObject.java
@@ -200,8 +200,8 @@ public class HemfPlusObject {
if (objectData.isContinuedRecord()) {
EmfPlusObject other;
HwmfObjectTableEntry entry =
ctx.getPlusObjectTableEntry(getObjectId());
- if (entry instanceof EmfPlusObject &&
- objectData.getClass().isInstance((other =
(EmfPlusObject)entry).getObjectData())
+ if (entry instanceof EmfPlusObject emfPlusObject &&
+ objectData.getClass().isInstance(other =
emfPlusObject.getObjectData())
) {
other.linkContinuedObject(objectData);
} else {
@@ -214,7 +214,11 @@ public class HemfPlusObject {
@Override
public void applyObject(HwmfGraphics ctx) {
- objectData.applyObject((HemfGraphics)ctx, continuedObjectData);
+ if (ctx instanceof HemfGraphics hemfCtx) {
+ objectData.applyObject(hemfCtx, continuedObjectData);
+ } else {
+ throw new IllegalArgumentException("can't apply object to
non-HemfGraphics context");
+ }
}
void linkContinuedObject(EmfPlusObjectData continueObject) {
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
index 7f1a5e37d1..ee32ff8044 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfPicture.java
@@ -125,8 +125,8 @@ public class HemfPicture implements Iterable<HemfRecord>,
GenericRecord {
header[0] = (HemfHeader) r;
}
r.setHeader(header[0]);
- if (r instanceof HwmfCharsetAware) {
-
((HwmfCharsetAware)r).setCharsetProvider(this::getDefaultCharset);
+ if (r instanceof HwmfCharsetAware charsetAware) {
+ charsetAware.setCharsetProvider(this::getDefaultCharset);
}
records.add(r);
});
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/Attachment.java
b/poi-scratchpad/src/main/java/org/apache/poi/hmef/Attachment.java
index 1e164dbaae..3a8ff52ac5 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/Attachment.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/Attachment.java
@@ -43,8 +43,7 @@ public final class Attachment {
protected void addAttribute(TNEFAttribute attr) {
attributes.add(attr);
- if(attr instanceof TNEFMAPIAttribute) {
- TNEFMAPIAttribute tnefMAPI = (TNEFMAPIAttribute)attr;
+ if(attr instanceof TNEFMAPIAttribute tnefMAPI) {
mapiAttributes.addAll( tnefMAPI.getMAPIAttributes() );
}
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/HMEFMessage.java
b/poi-scratchpad/src/main/java/org/apache/poi/hmef/HMEFMessage.java
index 26f5238310..84babda0fb 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/HMEFMessage.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/HMEFMessage.java
@@ -106,8 +106,7 @@ public final class HMEFMessage {
messageAttributes.add(attr);
- if (attr instanceof TNEFMAPIAttribute) {
- TNEFMAPIAttribute tnefMAPI = (TNEFMAPIAttribute) attr;
+ if (attr instanceof TNEFMAPIAttribute tnefMAPI) {
mapiAttributes.addAll(tnefMAPI.getMAPIAttributes());
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/TextStyleListing.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/TextStyleListing.java
index dba646860a..2b8b19aaec 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/TextStyleListing.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/TextStyleListing.java
@@ -53,15 +53,14 @@ public final class TextStyleListing {
int lastTextLen = -1;
for (Record slwtChild : slwtChildren) {
- if (slwtChild instanceof TextCharsAtom) {
- lastTextLen = ((TextCharsAtom)
slwtChild).getText().length();
+ if (slwtChild instanceof TextCharsAtom
textCharsAtom) {
+ lastTextLen =
textCharsAtom.getText().length();
}
- if (slwtChild instanceof TextBytesAtom) {
- lastTextLen = ((TextBytesAtom)
slwtChild).getText().length();
+ if (slwtChild instanceof TextBytesAtom
textBytesAtom) {
+ lastTextLen =
textBytesAtom.getText().length();
}
- if (slwtChild instanceof StyleTextPropAtom) {
- StyleTextPropAtom stpa =
(StyleTextPropAtom) slwtChild;
+ if (slwtChild instanceof StyleTextPropAtom
stpa) {
stpa.setParentTextSize(lastTextLen);
showStyleTextPropAtom(stpa);
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java
index abf3ac4f1f..f1c6ac36d3 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java
@@ -122,41 +122,41 @@ public class CurrentUserAtom {
public CurrentUserAtom(DirectoryNode dir) throws IOException {
// Decide how big it is
final Entry entry = dir.getEntry("Current User");
- if (!(entry instanceof DocumentEntry)) {
- throw new IllegalArgumentException("Had unexpected type of entry
for name: Current User: " + entry.getClass());
- }
- DocumentEntry docProps = (DocumentEntry) entry;
-
- // If it's clearly junk, bail out
- if(docProps.getSize() > 131072) {
- throw new CorruptPowerPointFileException("The Current User stream
is implausibly long. It's normally 28-200 bytes long, but was " +
docProps.getSize() + " bytes");
- }
-
- // Grab the contents
- try (InputStream in = dir.createDocumentInputStream("Current User")) {
- _contents = IOUtils.toByteArray(in, docProps.getSize(),
RecordAtom.getMaxRecordLength(),
- "RecordAtom.setMaxRecordLength()");
- }
+ if (entry instanceof DocumentEntry docProps) {
+ // If it's clearly junk, bail out
+ if(docProps.getSize() > 131072) {
+ throw new CorruptPowerPointFileException("The Current User
stream is implausibly long. It's normally 28-200 bytes long, but was " +
docProps.getSize() + " bytes");
+ }
- // See how long it is. If it's under 28 bytes long, we can't
- // read it
- if(_contents.length < 28) {
- boolean isPP95 = dir.hasEntryCaseInsensitive(PP95_DOCUMENT);
- // PPT95 has 4 byte size, then data
- if (!isPP95 && _contents.length >= 4) {
- int size = LittleEndian.getInt(_contents);
- isPP95 = (size + 4 == _contents.length);
+ // Grab the contents
+ try (InputStream in = dir.createDocumentInputStream("Current
User")) {
+ _contents = IOUtils.toByteArray(in, docProps.getSize(),
RecordAtom.getMaxRecordLength(),
+ "RecordAtom.setMaxRecordLength()");
}
- if (isPP95) {
- throw new OldPowerPointFormatException("Based on the Current
User stream, you seem to have supplied a PowerPoint95 file, which isn't
supported");
- } else {
- throw new CorruptPowerPointFileException("The Current User
stream must be at least 28 bytes long, but was only " + _contents.length);
+ // See how long it is. If it's under 28 bytes long, we can't
+ // read it
+ if(_contents.length < 28) {
+ boolean isPP95 = dir.hasEntryCaseInsensitive(PP95_DOCUMENT);
+ // PPT95 has 4 byte size, then data
+ if (!isPP95 && _contents.length >= 4) {
+ int size = LittleEndian.getInt(_contents);
+ isPP95 = (size + 4 == _contents.length);
+ }
+
+ if (isPP95) {
+ throw new OldPowerPointFormatException("Based on the
Current User stream, you seem to have supplied a PowerPoint95 file, which isn't
supported");
+ } else {
+ throw new CorruptPowerPointFileException("The Current User
stream must be at least 28 bytes long, but was only " + _contents.length);
+ }
}
+
+ // Set everything up
+ init();
+ } else {
+ throw new IllegalArgumentException("Had unexpected type of entry
for name: Current User: " + entry.getClass());
}
- // Set everything up
- init();
}
/**
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java
index fd4d65d28d..fe8e06d3f4 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PPDrawingGroup.java
@@ -135,9 +135,9 @@ public final class PPDrawingGroup extends RecordAtom {
public EscherDggRecord getEscherDggRecord(){
if(dgg == null){
- for(EscherRecord r : dggContainer){
- if(r instanceof EscherDggRecord){
- dgg = (EscherDggRecord)r;
+ for(EscherRecord r : dggContainer) {
+ if(r instanceof EscherDggRecord dggRecord) {
+ dgg = dggRecord;
break;
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
index a4f3358f07..58ca1694ad 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
@@ -305,16 +305,15 @@ public final class HSLFSlideShowImpl extends POIDocument
implements Closeable {
// Get the main document stream
final Entry entry = dir.getEntryCaseInsensitive(POWERPOINT_DOCUMENT);
- if (!(entry instanceof DocumentEntry)) {
+ if (entry instanceof DocumentEntry docProps) {
+ // Grab the document stream
+ int len = docProps.getSize();
+ try (InputStream is = dir.createDocumentInputStream(docProps)) {
+ _docstream = IOUtils.toByteArray(is, len, MAX_DOCUMENT_SIZE);
+ }
+ } else {
throw new IllegalArgumentException("Had unexpected type of entry
for name: " + POWERPOINT_DOCUMENT + ": " + entry.getClass());
}
- DocumentEntry docProps = (DocumentEntry) entry;
-
- // Grab the document stream
- int len = docProps.getSize();
- try (InputStream is = dir.createDocumentInputStream(docProps)) {
- _docstream = IOUtils.toByteArray(is, len, MAX_DOCUMENT_SIZE);
- }
}
/**
@@ -1064,8 +1063,8 @@ public final class HSLFSlideShowImpl extends POIDocument
implements Closeable {
if (_objects == null) {
List<HSLFObjectData> objects = new ArrayList<>();
for (Record r : _records) {
- if (r instanceof ExOleObjStg) {
- objects.add(new HSLFObjectData((ExOleObjStg) r));
+ if (r instanceof ExOleObjStg exOleObjStg) {
+ objects.add(new HSLFObjectData(exOleObjStg));
}
}
_objects = objects.toArray(new HSLFObjectData[0]);
@@ -1080,10 +1079,11 @@ public final class HSLFSlideShowImpl extends
POIDocument implements Closeable {
throw new CorruptPowerPointFileException("Did not have a valid
record: null");
}
if (record.getRecordType() == RecordTypes.Document.typeID) {
- if (!(record instanceof Document)) {
+ if (record instanceof Document dr) {
+ documentRecord = dr;
+ } else {
throw new CorruptPowerPointFileException("Did not have a
Document: " + record);
}
- documentRecord = (Document) record;
break;
}
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
index c812f0df6f..b0462ceafa 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
@@ -575,14 +575,14 @@ public final class HSLFTextParagraph implements
TextParagraph<HSLFShape,HSLFText
} else {
setBullet(true);
for (Object ostyle : styles) {
- if (ostyle instanceof Number) {
- setBulletSize(((Number)ostyle).doubleValue());
- } else if (ostyle instanceof Color) {
- setBulletColor((Color)ostyle);
- } else if (ostyle instanceof Character) {
- setBulletChar((Character)ostyle);
- } else if (ostyle instanceof String) {
- setBulletFont((String)ostyle);
+ if (ostyle instanceof Number num) {
+ setBulletSize(num.doubleValue());
+ } else if (ostyle instanceof Color color) {
+ setBulletColor(color);
+ } else if (ostyle instanceof Character character) {
+ setBulletChar(character);
+ } else if (ostyle instanceof String str) {
+ setBulletFont(str);
} else if (ostyle instanceof AutoNumberingScheme) {
throw new HSLFException("setting bullet auto-numbering
scheme for HSLF not supported ... yet");
}
diff --git
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java
index 072a93a5c2..97af3b89e0 100644
---
a/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java
+++
b/poi-scratchpad/src/main/java/org/apache/poi/hslf/util/LocaleDateFormat.java
@@ -283,7 +283,7 @@ public final class LocaleDateFormat {
/**
* 10 - MMM-yy
*/
- ABBREVIATED_MONTH_AND_YEAR(isOldFmt () ? "MMM-yy" : "LLL-yy", null,
null),
+ ABBREVIATED_MONTH_AND_YEAR("LLL-yy", null, null),
/**
* 11 - Base short date followed by a space, followed by base time
with seconds removed.
* Seconds are removed by removing all "s" symbols and any symbol that
directly precedes an
@@ -350,21 +350,17 @@ public final class LocaleDateFormat {
int mappedFormatId = formatID;
if (mapFormatId == MapFormatId.PPT) {
Object mappedFormat = MapFormatPPT.mapFormatId(lcid, formatID);
- if (mappedFormat instanceof String) {
- return DateTimeFormatter.ofPattern((String)mappedFormat,loc);
+ if (mappedFormat instanceof String str) {
+ return DateTimeFormatter.ofPattern(str, loc);
} else {
mappedFormatId = (Integer)mappedFormat;
}
}
Object mappedFormat = MapFormatException.mapFormatId(lcid,
mappedFormatId);
- if (mappedFormat instanceof String) {
- return DateTimeFormatter.ofPattern((String)mappedFormat,loc);
+ if (mappedFormat instanceof String str) {
+ return DateTimeFormatter.ofPattern(str, loc);
} else {
return MapFormatBase.mapFormatId(loc, (Integer)mappedFormat);
}
}
-
- private static boolean isOldFmt() {
- return System.getProperty("java.version").startsWith("1.8");
- }
}
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java
b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java
index c568a66d52..36e8ba32dd 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/MAPIMessage.java
@@ -528,32 +528,32 @@ public class MAPIMessage extends POIReadOnlyDocument {
public void set7BitEncoding(String generalcharset, String htmlbodycharset,
String bodycharset) {
for (Chunk c : mainChunks.getChunks()) {
- if (c instanceof StringChunk) {
+ if (c instanceof StringChunk stringChunk) {
if (c.getChunkId() == MAPIProperty.BODY_HTML.id) {
if (htmlbodycharset != null) {
- ((StringChunk) c).set7BitEncoding(htmlbodycharset);
+ stringChunk.set7BitEncoding(htmlbodycharset);
}
} else if (c.getChunkId() == MAPIProperty.BODY.id) {
if (bodycharset != null) {
- ((StringChunk) c).set7BitEncoding(bodycharset);
+ stringChunk.set7BitEncoding(bodycharset);
}
} else if (generalcharset != null) {
- ((StringChunk) c).set7BitEncoding(generalcharset);
+ stringChunk.set7BitEncoding(generalcharset);
}
}
}
if (generalcharset != null) {
if (nameIdChunks != null) {
for (Chunk c : nameIdChunks.getChunks()) {
- if (c instanceof StringChunk) {
- ((StringChunk) c).set7BitEncoding(generalcharset);
+ if (c instanceof StringChunk stringChunk) {
+ stringChunk.set7BitEncoding(generalcharset);
}
}
}
for (RecipientChunks rc : recipientChunks) {
for (Chunk c : rc.getAll()) {
- if (c instanceof StringChunk) {
- ((StringChunk) c).set7BitEncoding(generalcharset);
+ if (c instanceof StringChunk stringChunk) {
+ stringChunk.set7BitEncoding(generalcharset);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]