1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-09 17:19: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 experimental extensions.
Classes and methods for XEPs that are in status 'experimental' or that should

View file

@ -83,6 +83,7 @@ public class IoTFieldsExtension implements ExtensionElement {
return xml;
}
@SuppressWarnings("JavaUtilDate")
public static IoTFieldsExtension buildFor(int seqNr, boolean done, NodeInfo nodeInfo,
List<? extends IoTDataField> data) {
TimestampElement timestampElement = new TimestampElement(new Date(), data);

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2017 Paul Schaub, 2019 Florian Schmaus
* Copyright 2017 Paul Schaub, 2019-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.
@ -167,6 +167,7 @@ public class JingleFileTransferChild implements JingleContentDescriptionChildEle
return new JingleFileTransferChild(date, desc, hash, mediaType, name, size, range);
}
@SuppressWarnings("JavaUtilDate")
public Builder setFile(File file) {
return setDate(new Date(file.lastModified()))
.setName(file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf("/") + 1))

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2017-2023 Florian Schmaus, 2016-2017 Fernando Ramirez
* Copyright © 2017-2024 Florian Schmaus, 2016-2017 Fernando Ramirez
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -387,6 +387,7 @@ public final class MamManager extends Manager {
return this;
}
@SuppressWarnings("JavaUtilDate")
public Builder limitResultsSince(Date start) {
if (start == null) {
return this;
@ -415,6 +416,7 @@ public final class MamManager extends Manager {
return this;
}
@SuppressWarnings("JavaUtilDate")
public Builder limitResultsBefore(Date end) {
if (end == null) {
return this;

View file

@ -114,6 +114,7 @@ public class SpoilerElement implements ExtensionElement {
* @param message message
* @return map of spoilers
*/
@SuppressWarnings("MixedMutabilityReturnType")
public static Map<String, String> getSpoilers(Message message) {
if (!containsSpoiler(message)) {
return Collections.emptyMap();

View file

@ -56,6 +56,7 @@ public class TimestampAffixElement implements NamedElement, AffixElement {
return EqualsUtil.equals(this, obj, (e, o) -> e.append(getTimestamp(), o.getTimestamp()));
}
@SuppressWarnings("JavaUtilDate")
@Override
public int hashCode() {
return timestamp.hashCode();

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2016 Fernando Ramirez, 2018-2020 Florian Schmaus
* Copyright 2016 Fernando Ramirez, 2018-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.
@ -46,6 +46,7 @@ public class FiltersTest extends MamTest {
return xml;
}
@SuppressWarnings("JavaUtilDate")
@Test
public void checkStartDateFilter() throws Exception {
Date date = new Date();
@ -61,6 +62,7 @@ public class FiltersTest extends MamTest {
assertEquals(getMamXMemberWith(fields, values), dataForm.toXML().toString());
}
@SuppressWarnings("JavaUtilDate")
@Test
public void checkEndDateFilter() throws Exception {
Date date = new Date();