1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 00:59:39 +02:00

Bump to Gradle 8.10.2, require Java 11

Bump Gradle from 6.8.3 to 8.10.2 and increase the minimum required
Java version from 8 to 11 (SMACK-953).

The switch from Java 8 to 11 caused some Bytecode portability issues
regarding NIO Buffers. Java changed with version 9 the return type of
some subclasses of Buffer to return the specific Buffer type instead
of the Buffer superclass [JDK-4774077]. For example, ByteBuffer.filp()
previously returned Buffer, while it does return ByteBuffer now.

This sensible change was not reflected by the Android API [1], which
means that AnimalSniffer rightfully started to complain that there is
no method "ByteBuffer ByteBuffer.flip()" in Android, there is only
"Buffer ByteBuffer.flip()", and those are incompatible methods on
Java's Bytecode layer.

As workaround, this changes

    return charBuffer.flip().toString();

to

    ((java.nio.Buffer) charBuffer).flip();
    return charBuffer.toString();

to restore the Bytecode portability between Android and Java.

Errorprone also got new checks, of which JavaUtilDate and JdkObsolete
are wroth mentioning.

JavaUtilData basically strongly recommends to use Java's newer time
API over java.util.Date. But since Smack was Java 8 until now,
j.u.Date is widely used.

Similar JdkObsolete mentions obsolete JDK APIs, like data structures
like Vector and Stack. But mostly LinkedList, which should usually be
replaced by ArrayList. And this is what this commit largely does.

JDK-4774077: https://bugs.openjdk.org/browse/JDK-4774077
1: https://issuetracker.google.com/issues/369219141
This commit is contained in:
Florian Schmaus 2024-09-25 11:43:47 +02:00
parent d8d066b831
commit 1e5d34eacf
136 changed files with 1161 additions and 1220 deletions

View file

@ -1,3 +1,8 @@
plugins {
id 'org.igniterealtime.smack.java-common-conventions'
id 'org.igniterealtime.smack.android-conventions'
}
description = """\
Smack API for XEP-0373: OpenPGP for XMPP."""
@ -14,4 +19,7 @@ dependencies {
testFixturesApi(testFixtures(project(":smack-core")))
testImplementation group: 'commons-io', name: 'commons-io', version: "$commonsIoVersion"
// TODO: Migrate Junit4 tests to Junit5.
testImplementation "org.junit.vintage:junit-vintage-engine:$junitVersion"
}

View file

@ -362,6 +362,7 @@ public class OpenPgpContact {
* @throws SmackException.NoResponseException in case the server doesn't respond.
* @throws IOException IO is dangerous.
*/
@SuppressWarnings("JavaUtilDate")
public void updateKeys(XMPPConnection connection, PublicKeysListElement metadata)
throws InterruptedException, SmackException.NotConnectedException, SmackException.NoResponseException,
IOException {

View file

@ -246,6 +246,7 @@ public final class OpenPgpManager extends Manager {
* @throws SmackException.NotLoggedInException if we are not logged in.
* @throws PGPException if something goes wrong during key loading/generating
*/
@SuppressWarnings("JavaUtilDate")
public void announceSupportAndPublish()
throws NoSuchAlgorithmException, NoSuchProviderException, InterruptedException,
PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException,

View file

@ -71,6 +71,7 @@ public class OpenPgpSelf extends OpenPgpContact {
* @throws IOException IO is dangerous
* @throws PGPException PGP is brittle
*/
@SuppressWarnings("JavaUtilDate")
public PGPSecretKeyRing getSigningKeyRing() throws IOException, PGPException {
PGPSecretKeyRingCollection secretKeyRings = getSecretKeys();
if (secretKeyRings == null) {

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017-2019 Florian Schmaus, 2018 Paul Schaub.
* Copyright 2017-2024 Florian Schmaus, 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -45,6 +45,7 @@ public abstract class EncryptedOpenPgpContentElement extends OpenPgpContentEleme
this.rpad = Objects.requireNonNull(rpad);
}
@SuppressWarnings("JavaUtilDate")
protected EncryptedOpenPgpContentElement(Set<? extends Jid> to, List<ExtensionElement> payload) {
super(Objects.requireNonNullNorEmpty(
to, "Encrypted OpenPGP content elements must have at least one 'to' attribute."),

View file

@ -132,7 +132,7 @@ public abstract class OpenPgpContentElement implements ExtensionElement {
* @param <PE> type of the ExtensionElement.
* @return the extension, or <code>null</code> if it doesn't exist.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace) {
if (namespace == null) {
return null;

View file

@ -133,12 +133,13 @@ public final class PublicKeysListElement implements ExtensionElement {
return xml;
}
@SuppressWarnings("JavaUtilDate")
@Override
public int hashCode() {
return getV4Fingerprint().hashCode() + 3 * getDate().hashCode();
}
@SuppressWarnings("UndefinedEquals")
@SuppressWarnings({"UndefinedEquals", "JavaUtilDate"})
// TODO: Fix the UndefinedEquals due using Date.equals(Date)
@Override
public boolean equals(Object o) {

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017-2021 Florian Schmaus, 2018 Paul Schaub.
* Copyright 2017-2024 Florian Schmaus, 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,9 +18,9 @@ package org.jivesoftware.smackx.ox.provider;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
@ -87,7 +87,7 @@ public abstract class OpenPgpContentElementProvider<O extends OpenPgpContentElem
Set<Jid> to = new HashSet<>();
Date timestamp = null;
String rpad = null;
List<ExtensionElement> payload = new LinkedList<>();
List<ExtensionElement> payload = new ArrayList<>();
outerloop: while (true) {
XmlPullParser.Event tag = parser.next();

View file

@ -118,6 +118,7 @@ public class FileBasedOpenPgpMetadataStore extends AbstractOpenPgpMetadataStore
}
}
@SuppressWarnings("JavaUtilDate")
static void writeFingerprintsAndDates(Map<OpenPgpV4Fingerprint, Date> data, File destination)
throws IOException {
if (data == null || data.isEmpty()) {

View file

@ -124,6 +124,7 @@ public class OpenPgpPubSubUtil {
* @throws SmackException.NotConnectedException if we are not connected.
* @throws SmackException.NoResponseException if the server doesn't respond.
*/
@SuppressWarnings("JavaUtilDate")
public static void publishPublicKey(PepManager pepManager, PubkeyElement pubkeyElement, OpenPgpV4Fingerprint fingerprint)
throws InterruptedException, PubSubException.NotALeafNodeException,
XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
@ -464,8 +465,7 @@ public class OpenPgpPubSubUtil {
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException |
NoSuchFieldException e) {
LOGGER.log(Level.SEVERE, "Using reflections to create a LeafNode and put it into PubSubManagers nodeMap failed.", e);
throw new AssertionError(e);
throw new LinkageError("Using reflections to create a LeafNode and put it into PubSubManagers nodeMap failed.", e);
}
}
}

View file

@ -51,6 +51,7 @@ public class OpenPgpElementTest extends SmackTestSuite {
private final Set<Jid> recipients;
// 2014-07-10T15:06:00.000+00:00
@SuppressWarnings("JavaUtilDate")
private static final Date testDate = new Date(1405004760000L);
public OpenPgpElementTest() throws XmppStringprepException {

View file

@ -300,6 +300,7 @@ public class OpenPgpStoreTest extends SmackTestSuite {
*/
@Test
@SuppressWarnings("JavaUtilDate")
public void t10_meta_emptyStoreTest() throws IOException {
assertNotNull(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice));
assertTrue(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice).isEmpty());
@ -324,6 +325,7 @@ public class OpenPgpStoreTest extends SmackTestSuite {
}
@Test
@SuppressWarnings("JavaUtilDate")
public void t11_key_fetchDateTest() throws IOException {
Map<OpenPgpV4Fingerprint, Date> fetchDates1 = openPgpStoreInstance1.getPublicKeyFetchDates(alice);

View file

@ -72,6 +72,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
}
@Test
@SuppressWarnings("JavaUtilDate")
public void encryptDecryptTest() throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException, MissingUserIdOnKeyException, XmlPullParserException {
// Initialize

View file

@ -70,6 +70,7 @@ public class PublicKeysListElementTest extends SmackTestSuite {
}
@Test
@SuppressWarnings("JavaUtilDate")
public void listBuilderRefusesDuplicatesTest() {
PublicKeysListElement.Builder builder = PublicKeysListElement.builder();
String fp40 = "49545320414c4c2041424f555420444120484558";

View file

@ -66,6 +66,7 @@ public class OXInstantMessagingManagerTest extends SmackTestSuite {
}
@Test
@SuppressWarnings("JavaUtilDate")
public void test() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException,
NoSuchProviderException, SmackException, MissingUserIdOnKeyException, InterruptedException, XMPPException,
XmlPullParserException {