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 extensions.
Classes and methods that implement support for the various XMPP XEPs

View file

@ -16,8 +16,8 @@
*/
package org.jivesoftware.smackx.bytestreams.ibb;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
@ -135,7 +135,7 @@ public final class InBandBytestreamManager extends Manager implements Bytestream
* list of listeners that respond to all In-Band Bytestream requests if there are no user
* specific listeners for that request
*/
private final List<BytestreamListener> allRequestListeners = Collections.synchronizedList(new LinkedList<BytestreamListener>());
private final List<BytestreamListener> allRequestListeners = Collections.synchronizedList(new ArrayList<BytestreamListener>());
/* listener that handles all incoming In-Band Bytestream requests */
private final InitiationListener initiationListener;
@ -162,7 +162,7 @@ public final class InBandBytestreamManager extends Manager implements Bytestream
* list containing session IDs of In-Band Bytestream open packets that should be ignored by the
* InitiationListener
*/
private final List<String> ignoredBytestreamRequests = Collections.synchronizedList(new LinkedList<String>());
private final List<String> ignoredBytestreamRequests = Collections.synchronizedList(new ArrayList<String>());
/**
* Returns the InBandBytestreamManager to handle In-Band Bytestreams for a given

View file

@ -22,7 +22,6 @@ import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -128,7 +127,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* list of listeners that respond to all bytestream requests if there are not user specific
* listeners for that request
*/
private final List<BytestreamListener> allRequestListeners = Collections.synchronizedList(new LinkedList<BytestreamListener>());
private final List<BytestreamListener> allRequestListeners = Collections.synchronizedList(new ArrayList<BytestreamListener>());
/* listener that handles all incoming bytestream requests */
private final InitiationListener initiationListener;
@ -154,7 +153,7 @@ public final class Socks5BytestreamManager extends Manager implements Bytestream
* list containing session IDs of SOCKS5 Bytestream initialization packets that should be
* ignored by the InitiationListener
*/
private final List<String> ignoredBytestreamRequests = Collections.synchronizedList(new LinkedList<String>());
private final List<String> ignoredBytestreamRequests = Collections.synchronizedList(new ArrayList<String>());
/**
* Returns the Socks5BytestreamManager to handle SOCKS5 Bytestreams for a given

View file

@ -26,12 +26,12 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -107,7 +107,7 @@ public class Socks5Proxy {
private final Map<String, Socket> connectionMap = new ConcurrentHashMap<>();
/* list of digests connections should be stored */
private final List<String> allowedConnections = Collections.synchronizedList(new LinkedList<String>());
private final List<String> allowedConnections = Collections.synchronizedList(new ArrayList<String>());
private final Set<InetAddress> localAddresses = new LinkedHashSet<>(4);
@ -345,7 +345,7 @@ public class Socks5Proxy {
*/
public List<InetAddress> getLocalAddresses() {
synchronized (localAddresses) {
return new LinkedList<>(localAddresses);
return new ArrayList<>(localAddresses);
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2009 Jonas Ådahl, 2011-2022 Florian Schmaus
* Copyright © 2009 Jonas Ådahl, 2011-2024 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,12 +19,12 @@ package org.jivesoftware.smackx.caps;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -555,7 +555,7 @@ public final class EntityCapsManager extends Manager {
if (connection != null)
JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion));
final List<Identity> identities = new LinkedList<>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
final List<Identity> identities = new ArrayList<>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
sdm.setNodeInformationProvider(localNodeVer, new AbstractNodeInformationProvider() {
List<String> features = sdm.getFeatures();
List<DataForm> packetExtensions = sdm.getExtendedInfo();

View file

@ -22,7 +22,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -772,7 +771,7 @@ public final class ServiceDiscoveryManager extends Manager {
return serviceDiscoInfo;
}
}
serviceDiscoInfo = new LinkedList<>();
serviceDiscoInfo = new ArrayList<>();
// Send the disco packet to the server itself
DiscoverInfo info;
try {

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smackx.disco.packet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@ -184,7 +183,7 @@ public class DiscoverInfo extends IQ implements DiscoverInfoView {
* @return true if duplicate identities where found, otherwise false
*/
public boolean containsDuplicateIdentities() {
List<Identity> checkedIdentities = new LinkedList<>();
List<Identity> checkedIdentities = new ArrayList<>(identities.size());
for (Identity i : identities) {
for (Identity i2 : checkedIdentities) {
if (i.equals(i2))

View file

@ -16,9 +16,9 @@
*/
package org.jivesoftware.smackx.disco.packet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.jivesoftware.smack.packet.IQ;
@ -40,7 +40,7 @@ public class DiscoverItems extends IQ {
public static final String ELEMENT = QUERY_ELEMENT;
public static final String NAMESPACE = "http://jabber.org/protocol/disco#items";
private final List<Item> items = new LinkedList<>();
private final List<Item> items = new ArrayList<>();
private String node;
public DiscoverItems() {

View file

@ -17,8 +17,8 @@
package org.jivesoftware.smackx.iqregister.provider;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@ -40,7 +40,7 @@ public class RegistrationProvider extends IqProvider<Registration> {
public Registration parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
String instruction = null;
Map<String, String> fields = new HashMap<>();
List<XmlElement> packetExtensions = new LinkedList<>();
List<XmlElement> packetExtensions = new ArrayList<>();
outerloop:
while (true) {
XmlPullParser.Event eventType = parser.next();

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2021 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2021-2024 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -24,7 +24,7 @@ import org.jivesoftware.smack.util.StringUtils;
/**
* A Version IQ packet, which is used by XMPP clients to discover version information
* about the software running at another entity's JID.<p>
* about the software running at another entity's JID.
*
* @author Gaston Dombiak
*/

View file

@ -37,6 +37,7 @@ public class IdleElement implements ExtensionElement {
/**
* Create a new IdleElement with the current date as date of last user interaction.
*/
@SuppressWarnings("JavaUtilDate")
public IdleElement() {
this(new Date());
}

View file

@ -101,9 +101,7 @@ public final class MucEnterConfiguration {
/**
* Set the presence used to join the MUC room.
* <p>
* The consumer must not modify the presence type, otherwise an {@link IllegalArgumentException} will be thrown.
* <p>
*
* @param presenceBuilderConsumer a consumer which will be passed the presence build.
* @return a reference to this builder.

View file

@ -1842,7 +1842,7 @@ public class MultiUserChat {
/**
* Returns the presence info for a particular user, or <code>null</code> if the user
* is not in the room.<p>
* is not in the room.
*
* @param user the room occupant to search for his presence. The format of user must
* be: roomName@service/nickname (e.g. darkcave@macbeth.shakespeare.lit/thirdwitch).
@ -1856,7 +1856,7 @@ public class MultiUserChat {
/**
* Returns the Occupant information for a particular occupant, or <code>null</code> if the
* user is not in the room. The Occupant object may include information such as full
* JID of the user as well as the role and affiliation of the user in the room.<p>
* JID of the user as well as the role and affiliation of the user in the room.
*
* @param user the room occupant to search for his presence. The format of user must
* be: roomName@service/nickname (e.g. darkcave@macbeth.shakespeare.lit/thirdwitch).

View file

@ -108,6 +108,7 @@ public final class MultiUserChatManager extends Manager {
final WeakReference<XMPPConnection> weakRefConnection = new WeakReference<XMPPConnection>(connection);
ServiceDiscoveryManager.getInstanceFor(connection).setNodeInformationProvider(DISCO_NODE,
new AbstractNodeInformationProvider() {
@SuppressWarnings({"JavaUtilDate", "MixedMutabilityReturnType"})
@Override
public List<DiscoverItems.Item> getNodeItems() {
XMPPConnection connection = weakRefConnection.get();

View file

@ -109,6 +109,7 @@ public class ItemPublishEvent<T extends Item> extends SubscriptionEvent {
return originalDate;
}
@SuppressWarnings("JavaUtilDate")
@Override
public String toString() {
return getClass().getName() + " [subscriptions: " + getSubscriptions() + "], [Delayed: " +

View file

@ -49,7 +49,7 @@ public class PubSub extends IQ {
setType(type);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public <PE extends XmlElement> PE getExtension(PubSubElementType elem) {
return (PE) getExtensionElement(elem.getElementName(), elem.getNamespace().getXmlns());
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2021 Florian Schmaus
* Copyright © 2014-2024 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,8 +16,8 @@
*/
package org.jivesoftware.smackx.rsm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import org.jivesoftware.smack.packet.XmlElement;
@ -29,7 +29,7 @@ import org.jivesoftware.smackx.rsm.packet.RSMSet.PageDirection;
public class RSMManager {
Collection<XmlElement> page(int max) {
List<XmlElement> packetExtensions = new LinkedList<>();
List<XmlElement> packetExtensions = new ArrayList<>();
packetExtensions.add(new RSMSet(max));
return packetExtensions;
}
@ -45,7 +45,7 @@ public class RSMManager {
throw new IllegalArgumentException("returnedExtensions must no be null");
}
if (additionalExtensions == null) {
additionalExtensions = new LinkedList<>();
additionalExtensions = new ArrayList<>();
}
RSMSet resultRsmSet = PacketUtil.extensionElementFrom(returnedExtensions, RSMSet.ELEMENT, RSMSet.NAMESPACE);
if (resultRsmSet == null) {

View file

@ -45,6 +45,7 @@ import org.jxmpp.util.XmppDateTime;
public class StreamInitiationProvider extends IqProvider<StreamInitiation> {
private static final Logger LOGGER = Logger.getLogger(StreamInitiationProvider.class.getName());
@SuppressWarnings("JavaUtilDate")
@Override
public StreamInitiation parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
// si

View file

@ -22,8 +22,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.util.SmackTestSuite;
@ -218,7 +218,7 @@ public class EntityCapsManagerTest extends SmackTestSuite {
di.to(JidCreate.from("juliet@capulet.lit/chamber"));
di.ofType(IQ.Type.result);
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
Collection<DiscoverInfo.Identity> identities = new ArrayList<DiscoverInfo.Identity>();
DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
identities.add(i);
i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");
@ -241,7 +241,7 @@ public class EntityCapsManagerTest extends SmackTestSuite {
di.to(")juliet@capulet.lit/chamber");
di.ofType(IQ.Type.result);
Collection<DiscoverInfo.Identity> identities = new LinkedList<DiscoverInfo.Identity>();
Collection<DiscoverInfo.Identity> identities = new ArrayList<DiscoverInfo.Identity>();
DiscoverInfo.Identity i = new DiscoverInfo.Identity("client", "pc", "Psi 0.11", "en");
identities.add(i);
i = new DiscoverInfo.Identity("client", "pc", "Ψ 0.11", "el");

View file

@ -89,6 +89,7 @@ public class Protocol {
public boolean printProtocol = false;
// responses to requests are taken form this queue
@SuppressWarnings("JdkObsolete")
private final Queue<Stanza> responses = new LinkedList<>();
// list of verifications