Skip to content

Commit 966799a

Browse files
authored
TIKA-4128 -- bump to Java 11 (apache#1334)
* TIKA-4128 -- bump to Java 11
1 parent 796538b commit 966799a

File tree

23 files changed

+61
-97
lines changed

23 files changed

+61
-97
lines changed

.github/workflows/main-jdk11-build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
name: main jdk11 build
1919

2020
on:
21+
pull_request:
22+
branches: [ main ]
2123
push:
2224
branches: [ main ]
2325

.github/workflows/main-jdk8-build.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

CHANGES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Release 2.9.1 - ??
1+
Release 3.0.0-BETA - ??
2+
3+
* Require Java 11 (TIKA-4128).
24

35
* Fix bug in DateUtils that stripped timezone information from
46
incoming Calendar objects (TIKA-4126).

tika-batch/src/main/java/org/apache/tika/util/ClassLoaderUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.tika.util;
1818

19+
import java.lang.reflect.InvocationTargetException;
20+
1921
public class ClassLoaderUtil {
2022

2123
@SuppressWarnings("unchecked")
@@ -26,11 +28,12 @@ public static <T> T buildClass(Class<T> iface, String className) {
2628
try {
2729
clazz = loader.loadClass(className);
2830
if (iface.isAssignableFrom(clazz)) {
29-
return (T) clazz.newInstance();
31+
return (T) clazz.getDeclaredConstructor().newInstance();
3032
}
3133
throw new IllegalArgumentException(
3234
iface + " is not assignable from " + className);
33-
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
35+
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
36+
NoSuchMethodException | InvocationTargetException e) {
3437
throw new RuntimeException(e);
3538
}
3639

tika-core/src/main/java/org/apache/tika/config/ConfigBase.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ private static <T> T buildClass(Node node, String elementName, Class itemClass)
202202
elementName + " with class name " + className + " must be of type '" +
203203
itemClass.getName() + "'");
204204
}
205-
return (T) clazz.newInstance();
206-
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
205+
return (T) clazz.getDeclaredConstructor().newInstance();
206+
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException |
207+
NoSuchMethodException | InvocationTargetException e) {
207208
throw new TikaConfigException("problem loading " + elementName +
208209
" with class " + itemClass.getName(), e);
209210
}

tika-core/src/main/java/org/apache/tika/config/Param.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ public static <T> Param<T> load(Node node) throws TikaConfigException {
193193
private static <T> void loadObject(Param<T> ret, Node root, Class clazz) throws TikaConfigException {
194194

195195
try {
196-
ret.actualValue = (T)clazz.newInstance();
197-
} catch (InstantiationException | IllegalAccessException e) {
196+
ret.actualValue = (T)clazz.getDeclaredConstructor().newInstance();
197+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
198+
InvocationTargetException e) {
198199
throw new TikaConfigException("can't build class: " + clazz, e);
199200
}
200201

tika-core/src/main/java/org/apache/tika/config/TikaConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ T loadOne(Element element, MimeTypes mimeTypes, ServiceLoader loader)
800800
T newInstance(Class<? extends T> loadedClass)
801801
throws IllegalAccessException, InstantiationException, NoSuchMethodException,
802802
InvocationTargetException {
803-
return loadedClass.newInstance();
803+
return loadedClass.getDeclaredConstructor().newInstance();
804804
}
805805

806806
/**
@@ -987,7 +987,7 @@ Parser newInstance(Class<? extends Parser> loadedClass)
987987
Constructor ctor = loadedClass.getConstructor(EncodingDetector.class);
988988
parser = (Parser) ctor.newInstance(encodingDetector);
989989
} else {
990-
parser = loadedClass.newInstance();
990+
parser = loadedClass.getDeclaredConstructor().newInstance();
991991
}
992992

993993
if (parser instanceof RenderingParser) {

tika-core/src/main/java/org/apache/tika/fork/ClassLoaderProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected synchronized Class<?> findClass(String name) throws ClassNotFoundExcep
125125

126126
private void definePackageIfNecessary(String className, Class<?> clazz) {
127127
String packageName = toPackageName(className);
128-
if (packageName != null && getPackage(packageName) == null) {
128+
if (packageName != null && getDefinedPackage(packageName) == null) {
129129
definePackage(packageName, null, null, null, null, null, null, null);
130130
}
131131
}

tika-core/src/main/java/org/apache/tika/utils/ServiceLoaderUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public static <T> T newInstance(String className) {
5555
*/
5656
public static <T> T newInstance(String className, ClassLoader loader) {
5757
try {
58-
return ((Class<T>) Class.forName(className, true, loader)).newInstance();
59-
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
58+
return ((Class<T>) Class.forName(className, true, loader)).getDeclaredConstructor().newInstance();
59+
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
60+
NoSuchMethodException | InvocationTargetException e) {
6061
throw new RuntimeException(e);
6162
}
6263
}
@@ -77,11 +78,12 @@ public static <T> T newInstance(Class klass, ServiceLoader loader) {
7778
Constructor<T> constructor = klass.getDeclaredConstructor(ServiceLoader.class);
7879
return constructor.newInstance(loader);
7980
} catch (NoSuchMethodException e) {
80-
return (T)klass.newInstance();
81+
return (T)klass.getDeclaredConstructor().newInstance();
8182
} catch (InvocationTargetException e) {
8283
throw new RuntimeException(e);
8384
}
84-
} catch (InstantiationException | IllegalAccessException e) {
85+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
86+
InvocationTargetException e) {
8587
throw new RuntimeException(e);
8688
}
8789
}

tika-core/src/main/java/org/apache/tika/utils/XMLReaderUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,8 @@ private static void trySetXercesSecurityManager(DocumentBuilderFactory factory)
707707
//"com.sun.org.apache.xerces.internal.util.SecurityManager",
708708
XERCES_SECURITY_MANAGER}) {
709709
try {
710-
Object mgr = Class.forName(securityManagerClassName).newInstance();
710+
Object mgr =
711+
Class.forName(securityManagerClassName).getDeclaredConstructor().newInstance();
711712
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit",
712713
Integer.TYPE);
713714
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
@@ -750,7 +751,8 @@ private static void trySetXercesSecurityManager(SAXParser parser) {
750751
//"com.sun.org.apache.xerces.internal.util.SecurityManager",
751752
XERCES_SECURITY_MANAGER}) {
752753
try {
753-
Object mgr = Class.forName(securityManagerClassName).newInstance();
754+
Object mgr =
755+
Class.forName(securityManagerClassName).getDeclaredConstructor().newInstance();
754756
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
755757
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
756758

@@ -902,7 +904,8 @@ private static PoolSAXParser buildPoolParser(int generation, SAXParser parser) {
902904
}
903905
boolean hasSecurityManager = false;
904906
try {
905-
Object mgr = Class.forName(XERCES_SECURITY_MANAGER).newInstance();
907+
Object mgr =
908+
Class.forName(XERCES_SECURITY_MANAGER).getDeclaredConstructor().newInstance();
906909
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
907910
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
908911

tika-core/src/test/java/org/apache/tika/parser/mock/MockParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private void throwIt(String className, String msg)
417417
Throwable t = null;
418418
if (msg == null || msg.equals("")) {
419419
try {
420-
t = (Throwable) Class.forName(className).newInstance();
420+
t = (Throwable) Class.forName(className).getDeclaredConstructor().newInstance();
421421
} catch (Exception e) {
422422
throw new RuntimeException("couldn't create throwable class:" + className, e);
423423
}

tika-eval/tika-eval-core/src/test/java/org/apache/tika/eval/core/tokens/TokenCounterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void testCJKFilter() throws Exception {
110110
ts.end();
111111
ts.close();
112112
assertEquals(7, tokens.size());
113-
assertEquals(new Integer(1), tokens.get("林斯"));
113+
assertEquals(Integer.valueOf(1), tokens.get("林斯"));
114114
}
115115

116116
private String generateString() {

tika-parent/pom.xml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@
281281
</contributors>
282282

283283
<properties>
284-
<maven.compiler.source>1.8</maven.compiler.source>
285-
<maven.compiler.target>1.8</maven.compiler.target>
284+
<maven.compiler.source>11</maven.compiler.source>
285+
<maven.compiler.target>11</maven.compiler.target>
286286
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
287287
<project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
288288
<project.build.outputTimestamp>1692799752</project.build.outputTimestamp>
@@ -966,8 +966,7 @@
966966
<artifactId>maven-compiler-plugin</artifactId>
967967
<version>${maven.compiler.plugin.version}</version>
968968
<configuration>
969-
<source>${maven.compiler.source}</source>
970-
<target>${maven.compiler.target}</target>
969+
<release>11</release>
971970
</configuration>
972971
</plugin>
973972
<!--
@@ -1273,22 +1272,6 @@
12731272
</plugins>
12741273
</build>
12751274
</profile>
1276-
<profile>
1277-
<id>jdk9</id>
1278-
<activation>
1279-
<jdk>[1.9,)</jdk>
1280-
</activation>
1281-
<build>
1282-
<plugins>
1283-
<plugin>
1284-
<artifactId>maven-compiler-plugin</artifactId>
1285-
<configuration>
1286-
<release>8</release>
1287-
</configuration>
1288-
</plugin>
1289-
</plugins>
1290-
</build>
1291-
</profile>
12921275
<profile>
12931276
<id>ossindex-fail</id>
12941277
<!-- actually fail the build on vulnerabilities -->

tika-parsers/tika-parsers-ml/tika-parser-nlp-module/src/main/java/org/apache/tika/parser/ner/NamedEntityParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ private synchronized void initialize(ParseContext context) {
8888
className = className.trim();
8989
LOG.info("going to load, instantiate and bind the instance of {}", className);
9090
try {
91-
NERecogniser recogniser = (NERecogniser) Class.forName(className).newInstance();
91+
NERecogniser recogniser =
92+
(NERecogniser) Class.forName(className).getDeclaredConstructor().newInstance();
9293
LOG.info("{} is available ? {}", className, recogniser.isAvailable());
9394
if (recogniser.isAvailable()) {
9495
nerChain.add(recogniser);

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/onenote/FndStructureConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private FndStructureConstants() {
6060
}
6161

6262
static String nameOf(long type) {
63-
switch (new Long(type).intValue()) {
63+
switch (Long.valueOf(type).intValue()) {
6464
case (int) ObjectSpaceManifestRootFND:
6565
return "ObjectSpaceManifestRootFND";
6666
case (int) ObjectSpaceManifestListReferenceFND:

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/onenote/OneNotePtr.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ FileChunkReference deserializeVarFileChunkReference(long stpFormat, long cbForma
885885
long local8;
886886
long local16;
887887
long local32;
888-
switch (new Long(stpFormat).intValue()) {
888+
switch (Long.valueOf(stpFormat).intValue()) {
889889
case 0: // 8 bytes, uncompressed
890890
data.stp = deserializeLittleEndianLong();
891891
break;
@@ -906,7 +906,7 @@ FileChunkReference deserializeVarFileChunkReference(long stpFormat, long cbForma
906906
default:
907907
throw new TikaException("Unknown STP file node format " + stpFormat);
908908
}
909-
switch (new Long(cbFormat).intValue()) {
909+
switch (Long.valueOf(cbFormat).intValue()) {
910910
case 0: // 4 bytes, uncompressed
911911
local32 = deserializeLittleEndianInt();
912912
data.cb = local32;

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/onenote/fsshttpb/streamobj/DataElement.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.tika.parser.microsoft.onenote.fsshttpb.streamobj;
1919

2020
import java.io.IOException;
21+
import java.lang.reflect.InvocationTargetException;
2122
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Locale;
@@ -147,8 +148,9 @@ protected void deserializeItemsFromByteArray(byte[] byteArray, AtomicInteger cur
147148
if (DATA_ELEMENT_DATA_TYPE_MAPPING.containsKey(this.dataElementType)) {
148149
try {
149150
this.data = (DataElementData) DATA_ELEMENT_DATA_TYPE_MAPPING.get(this.dataElementType)
150-
.newInstance();
151-
} catch (InstantiationException | IllegalAccessException e) {
151+
.getDeclaredConstructor().newInstance();
152+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
153+
InvocationTargetException e) {
152154
throw new TikaException("Could not instantiate a " + dataElementType, e);
153155
}
154156

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/onenote/fsshttpb/streamobj/StreamObject.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.tika.parser.microsoft.onenote.fsshttpb.streamobj;
1919

2020
import java.io.IOException;
21+
import java.lang.reflect.InvocationTargetException;
2122
import java.util.ArrayList;
2223
import java.util.Arrays;
2324
import java.util.HashMap;
@@ -171,8 +172,10 @@ public static StreamObject parseStreamObject(StreamObjectHeaderStart header, byt
171172
Class headerTypeClass = streamObjectTypeMapping.get(header.type);
172173
StreamObject streamObject;
173174
try {
174-
streamObject = (StreamObject) headerTypeClass.newInstance();
175-
} catch (InstantiationException | IllegalAccessException e) {
175+
streamObject =
176+
(StreamObject) headerTypeClass.getDeclaredConstructor().newInstance();
177+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
178+
InvocationTargetException e) {
176179
throw new TikaException("Could not instantiate class " + headerTypeClass, e);
177180
}
178181

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/onenote/fsshttpb/streamobj/basic/BasicObject.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.tika.parser.microsoft.onenote.fsshttpb.streamobj.basic;
1919

2020
import java.io.IOException;
21+
import java.lang.reflect.InvocationTargetException;
2122
import java.util.List;
2223
import java.util.concurrent.atomic.AtomicInteger;
2324

@@ -39,11 +40,12 @@ public static <T extends BasicObject> T parse(byte[] byteArray, AtomicInteger in
3940
Class<T> clazz) throws TikaException,
4041
IOException {
4142
try {
42-
T fsshttpbObject = clazz.newInstance();
43+
T fsshttpbObject = clazz.getDeclaredConstructor().newInstance();
4344
index.addAndGet(fsshttpbObject.deserializeFromByteArray(byteArray, index.get()));
4445

4546
return fsshttpbObject;
46-
} catch (InstantiationException | IllegalAccessException e) {
47+
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
48+
InvocationTargetException e) {
4749
throw new TikaException("Could not parse basic object", e);
4850
}
4951
}

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/onenote/fsshttpb/streamobj/basic/ExGuid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public boolean equals(Object obj) {
142142
*/
143143
@Override
144144
public int hashCode() {
145-
return this.guid.hashCode() + new Integer(this.value).hashCode();
145+
return this.guid.hashCode() + Integer.valueOf(this.value).hashCode();
146146
}
147147

148148
/**

tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-text-module/src/test/java/org/apache/tika/parser/csv/CSVSnifferTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ private static List<CSVResult> sniff(char[] delimiters, byte[] bytes, Charset ch
7171
public void testCSVBasic() throws Exception {
7272
List<CSVResult> results = sniff(DELIMITERS, CSV_BASIC, StandardCharsets.UTF_8);
7373
assertEquals(2, results.size());
74-
assertEquals(new Character(','), results.get(0).getDelimiter());
74+
assertEquals(Character.valueOf(','), results.get(0).getDelimiter());
7575

7676
results = sniff(DELIMITERS, TSV_BASIC, StandardCharsets.UTF_8);
7777
assertEquals(2, results.size());
78-
assertEquals(new Character('\t'), results.get(0).getDelimiter());
78+
assertEquals(Character.valueOf('\t'), results.get(0).getDelimiter());
7979
}
8080

8181
@Test
@@ -91,11 +91,11 @@ public void testAllowWhiteSpacesAroundAQuote() throws Exception {
9191
List<CSVResult> results =
9292
sniff(DELIMITERS, ALLOW_SPACES_BEFORE_QUOTE, StandardCharsets.UTF_8);
9393
assertEquals(2, results.size());
94-
assertEquals(new Character(','), results.get(0).getDelimiter());
94+
assertEquals(Character.valueOf(','), results.get(0).getDelimiter());
9595

9696
results = sniff(DELIMITERS, ALLOW_SPACES_AFTER_QUOTE, StandardCharsets.UTF_8);
9797
assertEquals(2, results.size());
98-
assertEquals(new Character(','), results.get(0).getDelimiter());
98+
assertEquals(Character.valueOf(','), results.get(0).getDelimiter());
9999
}
100100

101101
@Test

tika-xmp/src/main/java/org/apache/tika/xmp/convert/TikaToXMP.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static ITikaToXMPConverter getConverter(String mimetype) throws TikaExcep
140140
Class<? extends ITikaToXMPConverter> clazz = getConverterMap().get(type);
141141
if (clazz != null) {
142142
try {
143-
converter = clazz.newInstance();
143+
converter = clazz.getDeclaredConstructor().newInstance();
144144
} catch (Exception e) {
145145
throw new TikaException(
146146
"TikaToXMP converter class cannot be instantiated for mimetype: " +

0 commit comments

Comments
 (0)