Skip to content

Commit

Permalink
TIKA-4128 -- bump to Java 11 (apache#1334)
Browse files Browse the repository at this point in the history
* TIKA-4128 -- bump to Java 11
  • Loading branch information
tballison authored Sep 13, 2023
1 parent 796538b commit 966799a
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main-jdk11-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
name: main jdk11 build

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/main-jdk8-build.yml

This file was deleted.

4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Release 2.9.1 - ??
Release 3.0.0-BETA - ??

* Require Java 11 (TIKA-4128).

* Fix bug in DateUtils that stripped timezone information from
incoming Calendar objects (TIKA-4126).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.tika.util;

import java.lang.reflect.InvocationTargetException;

public class ClassLoaderUtil {

@SuppressWarnings("unchecked")
Expand All @@ -26,11 +28,12 @@ public static <T> T buildClass(Class<T> iface, String className) {
try {
clazz = loader.loadClass(className);
if (iface.isAssignableFrom(clazz)) {
return (T) clazz.newInstance();
return (T) clazz.getDeclaredConstructor().newInstance();
}
throw new IllegalArgumentException(
iface + " is not assignable from " + className);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ private static <T> T buildClass(Node node, String elementName, Class itemClass)
elementName + " with class name " + className + " must be of type '" +
itemClass.getName() + "'");
}
return (T) clazz.newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
return (T) clazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException |
NoSuchMethodException | InvocationTargetException e) {
throw new TikaConfigException("problem loading " + elementName +
" with class " + itemClass.getName(), e);
}
Expand Down
5 changes: 3 additions & 2 deletions tika-core/src/main/java/org/apache/tika/config/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ public static <T> Param<T> load(Node node) throws TikaConfigException {
private static <T> void loadObject(Param<T> ret, Node root, Class clazz) throws TikaConfigException {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ T loadOne(Element element, MimeTypes mimeTypes, ServiceLoader loader)
T newInstance(Class<? extends T> loadedClass)
throws IllegalAccessException, InstantiationException, NoSuchMethodException,
InvocationTargetException {
return loadedClass.newInstance();
return loadedClass.getDeclaredConstructor().newInstance();
}

/**
Expand Down Expand Up @@ -987,7 +987,7 @@ Parser newInstance(Class<? extends Parser> loadedClass)
Constructor ctor = loadedClass.getConstructor(EncodingDetector.class);
parser = (Parser) ctor.newInstance(encodingDetector);
} else {
parser = loadedClass.newInstance();
parser = loadedClass.getDeclaredConstructor().newInstance();
}

if (parser instanceof RenderingParser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected synchronized Class<?> findClass(String name) throws ClassNotFoundExcep

private void definePackageIfNecessary(String className, Class<?> clazz) {
String packageName = toPackageName(className);
if (packageName != null && getPackage(packageName) == null) {
if (packageName != null && getDefinedPackage(packageName) == null) {
definePackage(packageName, null, null, null, null, null, null, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public static <T> T newInstance(String className) {
*/
public static <T> T newInstance(String className, ClassLoader loader) {
try {
return ((Class<T>) Class.forName(className, true, loader)).newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
return ((Class<T>) Class.forName(className, true, loader)).getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Expand All @@ -77,11 +78,12 @@ public static <T> T newInstance(Class klass, ServiceLoader loader) {
Constructor<T> constructor = klass.getDeclaredConstructor(ServiceLoader.class);
return constructor.newInstance(loader);
} catch (NoSuchMethodException e) {
return (T)klass.newInstance();
return (T)klass.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,8 @@ private static void trySetXercesSecurityManager(DocumentBuilderFactory factory)
//"com.sun.org.apache.xerces.internal.util.SecurityManager",
XERCES_SECURITY_MANAGER}) {
try {
Object mgr = Class.forName(securityManagerClassName).newInstance();
Object mgr =
Class.forName(securityManagerClassName).getDeclaredConstructor().newInstance();
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit",
Integer.TYPE);
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);
Expand Down Expand Up @@ -750,7 +751,8 @@ private static void trySetXercesSecurityManager(SAXParser parser) {
//"com.sun.org.apache.xerces.internal.util.SecurityManager",
XERCES_SECURITY_MANAGER}) {
try {
Object mgr = Class.forName(securityManagerClassName).newInstance();
Object mgr =
Class.forName(securityManagerClassName).getDeclaredConstructor().newInstance();
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);

Expand Down Expand Up @@ -902,7 +904,8 @@ private static PoolSAXParser buildPoolParser(int generation, SAXParser parser) {
}
boolean hasSecurityManager = false;
try {
Object mgr = Class.forName(XERCES_SECURITY_MANAGER).newInstance();
Object mgr =
Class.forName(XERCES_SECURITY_MANAGER).getDeclaredConstructor().newInstance();
Method setLimit = mgr.getClass().getMethod("setEntityExpansionLimit", Integer.TYPE);
setLimit.invoke(mgr, MAX_ENTITY_EXPANSIONS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private void throwIt(String className, String msg)
Throwable t = null;
if (msg == null || msg.equals("")) {
try {
t = (Throwable) Class.forName(className).newInstance();
t = (Throwable) Class.forName(className).getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new RuntimeException("couldn't create throwable class:" + className, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void testCJKFilter() throws Exception {
ts.end();
ts.close();
assertEquals(7, tokens.size());
assertEquals(new Integer(1), tokens.get("林斯"));
assertEquals(Integer.valueOf(1), tokens.get("林斯"));
}

private String generateString() {
Expand Down
23 changes: 3 additions & 20 deletions tika-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@
</contributors>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
<project.build.outputTimestamp>1692799752</project.build.outputTimestamp>
Expand Down Expand Up @@ -966,8 +966,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<release>11</release>
</configuration>
</plugin>
<!--
Expand Down Expand Up @@ -1273,22 +1272,6 @@
</plugins>
</build>
</profile>
<profile>
<id>jdk9</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ossindex-fail</id>
<!-- actually fail the build on vulnerabilities -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ private synchronized void initialize(ParseContext context) {
className = className.trim();
LOG.info("going to load, instantiate and bind the instance of {}", className);
try {
NERecogniser recogniser = (NERecogniser) Class.forName(className).newInstance();
NERecogniser recogniser =
(NERecogniser) Class.forName(className).getDeclaredConstructor().newInstance();
LOG.info("{} is available ? {}", className, recogniser.isAvailable());
if (recogniser.isAvailable()) {
nerChain.add(recogniser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private FndStructureConstants() {
}

static String nameOf(long type) {
switch (new Long(type).intValue()) {
switch (Long.valueOf(type).intValue()) {
case (int) ObjectSpaceManifestRootFND:
return "ObjectSpaceManifestRootFND";
case (int) ObjectSpaceManifestListReferenceFND:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ FileChunkReference deserializeVarFileChunkReference(long stpFormat, long cbForma
long local8;
long local16;
long local32;
switch (new Long(stpFormat).intValue()) {
switch (Long.valueOf(stpFormat).intValue()) {
case 0: // 8 bytes, uncompressed
data.stp = deserializeLittleEndianLong();
break;
Expand All @@ -906,7 +906,7 @@ FileChunkReference deserializeVarFileChunkReference(long stpFormat, long cbForma
default:
throw new TikaException("Unknown STP file node format " + stpFormat);
}
switch (new Long(cbFormat).intValue()) {
switch (Long.valueOf(cbFormat).intValue()) {
case 0: // 4 bytes, uncompressed
local32 = deserializeLittleEndianInt();
data.cb = local32;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.tika.parser.microsoft.onenote.fsshttpb.streamobj;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -147,8 +148,9 @@ protected void deserializeItemsFromByteArray(byte[] byteArray, AtomicInteger cur
if (DATA_ELEMENT_DATA_TYPE_MAPPING.containsKey(this.dataElementType)) {
try {
this.data = (DataElementData) DATA_ELEMENT_DATA_TYPE_MAPPING.get(this.dataElementType)
.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new TikaException("Could not instantiate a " + dataElementType, e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.tika.parser.microsoft.onenote.fsshttpb.streamobj;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -171,8 +172,10 @@ public static StreamObject parseStreamObject(StreamObjectHeaderStart header, byt
Class headerTypeClass = streamObjectTypeMapping.get(header.type);
StreamObject streamObject;
try {
streamObject = (StreamObject) headerTypeClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
streamObject =
(StreamObject) headerTypeClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new TikaException("Could not instantiate class " + headerTypeClass, e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.tika.parser.microsoft.onenote.fsshttpb.streamobj.basic;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

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

return fsshttpbObject;
} catch (InstantiationException | IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
throw new TikaException("Could not parse basic object", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public boolean equals(Object obj) {
*/
@Override
public int hashCode() {
return this.guid.hashCode() + new Integer(this.value).hashCode();
return this.guid.hashCode() + Integer.valueOf(this.value).hashCode();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ private static List<CSVResult> sniff(char[] delimiters, byte[] bytes, Charset ch
public void testCSVBasic() throws Exception {
List<CSVResult> results = sniff(DELIMITERS, CSV_BASIC, StandardCharsets.UTF_8);
assertEquals(2, results.size());
assertEquals(new Character(','), results.get(0).getDelimiter());
assertEquals(Character.valueOf(','), results.get(0).getDelimiter());

results = sniff(DELIMITERS, TSV_BASIC, StandardCharsets.UTF_8);
assertEquals(2, results.size());
assertEquals(new Character('\t'), results.get(0).getDelimiter());
assertEquals(Character.valueOf('\t'), results.get(0).getDelimiter());
}

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

results = sniff(DELIMITERS, ALLOW_SPACES_AFTER_QUOTE, StandardCharsets.UTF_8);
assertEquals(2, results.size());
assertEquals(new Character(','), results.get(0).getDelimiter());
assertEquals(Character.valueOf(','), results.get(0).getDelimiter());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static ITikaToXMPConverter getConverter(String mimetype) throws TikaExcep
Class<? extends ITikaToXMPConverter> clazz = getConverterMap().get(type);
if (clazz != null) {
try {
converter = clazz.newInstance();
converter = clazz.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new TikaException(
"TikaToXMP converter class cannot be instantiated for mimetype: " +
Expand Down
Loading

0 comments on commit 966799a

Please sign in to comment.