Skip to content

Commit

Permalink
Merge e8606b6 into 1df0763
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowdalic committed Jan 29, 2021
2 parents 1df0763 + e8606b6 commit 288834f
Show file tree
Hide file tree
Showing 136 changed files with 574 additions and 551 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ buildscript {

plugins {
id 'ru.vyarus.animalsniffer' version '1.5.0'
id 'net.ltgt.errorprone' version '1.1.1'
id 'net.ltgt.errorprone' version '1.3.0'
// Use e.g. "gradle <task> taskTree" to show its dependency tree.
id 'com.dorongold.task-tree' version '1.5'
id 'com.github.kt3k.coveralls' version '2.10.2'
Expand Down Expand Up @@ -218,6 +218,8 @@ allprojects {
// Disabled but should be re-enabled at some point
//'-Xep:InconsistentCapitalization:OFF',
'-Xep:MixedMutabilityReturnType:OFF',
// TODO: Re-enable once Smack's minimum Android SDK level is 26 or higher.
'-Xep:JavaUtilDate:OFF',
]
}
}
Expand Down Expand Up @@ -293,7 +295,7 @@ tasks.withType(Javadoc) {
testImplementation 'org.mockito:mockito-inline:3.3.3'
testImplementation 'com.jamesmurty.utils:java-xmlbuilder:1.2'

errorprone 'com.google.errorprone:error_prone_core:2.3.4'
errorprone 'com.google.errorprone:error_prone_core:2.5.1'
errorproneJavac('com.google.errorprone:javac:9+181-r4173-1')
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2017 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@

import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.logging.Logger;
Expand Down Expand Up @@ -113,14 +112,14 @@ public boolean isEnabled() {
@Override
public void onReceive(Context context, Intent intent) {
LOGGER.fine("Ping Alarm broadcast received");
Set<Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
Set<Map.Entry<XMPPConnection, ServerPingWithAlarmManager>> managers;
synchronized (ServerPingWithAlarmManager.class) {
// Make a copy to avoid ConcurrentModificationException when
// iterating directly over INSTANCES and the Set is modified
// concurrently by creating a new ServerPingWithAlarmManager.
managers = new HashSet<>(INSTANCES.entrySet());
}
for (Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
for (Map.Entry<XMPPConnection, ServerPingWithAlarmManager> entry : managers) {
XMPPConnection connection = entry.getKey();
if (entry.getValue().isEnabled()) {
LOGGER.fine("Calling pingServerIfNecessary for connection "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ private void challengeReceived(String challenge, boolean finalChallenge) throws
* Notification message saying that SASL authentication was successful. The next step
* would be to bind the resource.
* @param success result of the authentication.
* @throws SmackException if Smack detected an exceptional situation.
* @throws InterruptedException if the calling thread was interrupted.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws SmackSaslException if a SASL specific error occurred.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ synchronized void notifyConnectionError(Exception exception) {
*
* @param packet the stanza to process.
*/
protected void processStanza(Stanza packet) {
void processStanza(Stanza packet) {
if (packetFilter == null || packetFilter.accept(packet)) {
synchronized (this) {
if (resultQueue.size() == maxQueueSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public final class ModularXmppClientToServerConnection extends AbstractXMPPConne

private boolean featuresReceived;

protected boolean streamResumed;
private boolean streamResumed;

private GraphVertex<State> currentStateVertex;

Expand Down Expand Up @@ -264,7 +264,7 @@ protected void loginInternal(String username, String password, Resourcepart reso
walkStateGraph(walkStateGraphContext);
}

protected WalkStateGraphContext.Builder buildNewWalkTo(Class<? extends StateDescriptor> finalStateClass) {
private WalkStateGraphContext.Builder buildNewWalkTo(Class<? extends StateDescriptor> finalStateClass) {
return WalkStateGraphContext.builder(currentStateVertex.getElement().getStateDescriptor().getClass(), finalStateClass);
}

Expand All @@ -279,7 +279,7 @@ private void unwindState(State revertedState) {
revertedState.resetState();
}

protected void walkStateGraph(WalkStateGraphContext walkStateGraphContext)
private void walkStateGraph(WalkStateGraphContext walkStateGraphContext)
throws XMPPException, IOException, SmackException, InterruptedException {
// Save a copy of the current state
GraphVertex<State> previousStateVertex = currentStateVertex;
Expand Down Expand Up @@ -491,7 +491,7 @@ private void shutdown(boolean instant) {
}
}

protected SSLSession getSSLSession() {
private SSLSession getSSLSession() {
final XmppClientToServerTransport transport = activeTransport;
if (transport == null) {
return null;
Expand All @@ -505,7 +505,7 @@ protected void afterFeaturesReceived() {
notifyWaitingThreads();
}

protected void parseAndProcessElement(String element) {
private void parseAndProcessElement(String element) {
try {
XmlPullParser parser = PacketParserUtils.getParserFor(element);

Expand Down Expand Up @@ -556,11 +556,11 @@ protected void parseAndProcessElement(String element) {
}
}

protected synchronized void prepareToWaitForFeaturesReceived() {
private synchronized void prepareToWaitForFeaturesReceived() {
featuresReceived = false;
}

protected void waitForFeaturesReceived(String waitFor)
private void waitForFeaturesReceived(String waitFor)
throws InterruptedException, SmackException, XMPPException {
waitForConditionOrThrowConnectionException(() -> featuresReceived, waitFor);
}
Expand All @@ -571,7 +571,7 @@ protected AbstractStreamOpen getStreamOpen(DomainBareJid to, CharSequence from,
return streamOpenAndCloseFactory.createStreamOpen(to, from, id, lang);
}

protected void newStreamOpenWaitForFeaturesSequence(String waitFor) throws InterruptedException,
private void newStreamOpenWaitForFeaturesSequence(String waitFor) throws InterruptedException,
SmackException, XMPPException {
prepareToWaitForFeaturesReceived();

Expand Down Expand Up @@ -1028,7 +1028,7 @@ public boolean removeConnectionStateMachineListener(ConnectionStateMachineListen
return connectionStateMachineListeners.remove(connectionStateMachineListener);
}

protected void invokeConnectionStateMachineListener(ConnectionStateEvent connectionStateEvent) {
private void invokeConnectionStateMachineListener(ConnectionStateEvent connectionStateEvent) {
if (connectionStateMachineListeners.isEmpty()) {
return;
}
Expand Down Expand Up @@ -1056,7 +1056,7 @@ protected void connectInternal() throws SmackException, IOException, XMPPExcepti
walkStateGraph(walkStateGraphContext);
}

protected Map<String, Object> getFilterStats() {
private Map<String, Object> getFilterStats() {
Collection<XmppInputOutputFilter> filters;
synchronized (this) {
if (inputOutputFilters.isEmpty() && previousInputOutputFilters != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Alexander Wenckus
*
*/
@SuppressWarnings("BadImport")
public final class IQTypeFilter extends FlexibleStanzaTypeFilter<IQ> {

public static final StanzaFilter GET = new IQTypeFilter(Type.get);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @see org.jivesoftware.smack.packet.Message.Type
* @author Ward Harold
*/
@SuppressWarnings("BadImport")
public final class MessageTypeFilter extends FlexibleStanzaTypeFilter<Message> {

public static final StanzaFilter NORMAL = new MessageTypeFilter(Type.normal);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Florian Schmaus
* Copyright 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
* A filter for Presence types. Returns true only if the stanza is an Presence stanza and it matches the type provided in the
* constructor.
*/
@SuppressWarnings("BadImport")
public final class PresenceTypeFilter extends FlexibleStanzaTypeFilter<Presence> {

public static final PresenceTypeFilter AVAILABLE = new PresenceTypeFilter(Type.available);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus
* Copyright 2015-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package org.jivesoftware.smack.iqrequest;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IQ.Type;

/**
* Convenience class to create IQ requests handlers.
Expand All @@ -26,10 +25,10 @@ public abstract class AbstractIqRequestHandler implements IQRequestHandler {

private final String element;
private final String namespace;
private final Type type;
private final IQ.Type type;
private final Mode mode;

protected AbstractIqRequestHandler(String element, String namespace, Type type, Mode mode) {
protected AbstractIqRequestHandler(String element, String namespace, IQ.Type type, Mode mode) {
switch (type) {
case set:
case get:
Expand All @@ -52,7 +51,7 @@ public Mode getMode() {
}

@Override
public Type getType() {
public IQ.Type getType() {
return type;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2019-2020 Florian Schmaus
* Copyright 2019-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,12 +34,24 @@ public SmackParsingException(String message) {
super(message);
}

/**
* Deprecated, do not import.
* @deprecated do not import.
*/
@Deprecated
// TODO: Remove in Smack 4.6.
public static class SmackTextParseException extends SmackParsingException {
/**
*
*/
private static final long serialVersionUID = 1L;

/**
* Deprecated, do not use.
* @param parsingException the exception.
* @deprecated do not use, simply throw ParseException.
*/
@Deprecated
public SmackTextParseException(ParseException parsingException) {
super(parsingException);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
*/
package org.jivesoftware.smack.provider;

import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.text.ParseException;

import org.jivesoftware.smack.packet.Element;
import org.jivesoftware.smack.parsing.SmackParsingException;
import org.jivesoftware.smack.xml.XmlPullParserException;

public class AbstractProvider<E extends Element> {

Expand Down Expand Up @@ -55,4 +59,51 @@ protected AbstractProvider() {
public final Class<E> getElementClass() {
return elementClass;
}

public static final class TextParseException extends SmackParsingException {
/**
*
*/
private static final long serialVersionUID = 1L;

private final ParseException parseException;

private TextParseException(ParseException parseException) {
super(parseException);
this.parseException = parseException;
}

public ParseException getParseException() {
return parseException;
}
}

public static final class NumberFormatParseException extends SmackParsingException {
/**
*
*/
private static final long serialVersionUID = 1L;

private NumberFormatParseException(NumberFormatException numberFormatException) {
super(numberFormatException);
}
}

protected interface WrappableParser<E> {
E parse() throws XmlPullParserException, IOException, SmackParsingException, ParseException;
}

protected static <E> E wrapExceptions(WrappableParser<E> parser)
throws XmlPullParserException, IOException, SmackParsingException {
E e;
try {
e = parser.parse();
} catch (ParseException parseException) {
throw new TextParseException(parseException);
} catch (NumberFormatException numberFormatException) {
throw new NumberFormatParseException(numberFormatException);
}

return e;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.jivesoftware.smack.provider;

import java.io.IOException;
import java.text.ParseException;

import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.IqData;
Expand Down Expand Up @@ -50,7 +51,7 @@ public final I parse(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) t
final int initialDepth = parser.getDepth();
final XmlEnvironment xmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);

I e = parse(parser, initialDepth, xmlEnvironment);
I e = wrapExceptions(() -> parse(parser, initialDepth, xmlEnvironment));

// XPP3 calling convention assert: Parser should be at end tag of the consumed/parsed element
ParserUtils.forwardToEndTagOfDepth(parser, initialDepth);
Expand All @@ -59,11 +60,12 @@ public final I parse(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) t

@Override
public final I parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException {
throws XmlPullParserException, IOException, SmackParsingException, ParseException {
// Old-style IQ parsers do not need IqData.
return parse(parser, initialDepth, xmlEnvironment);
}

public abstract I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException;
public abstract I parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
throws XmlPullParserException, IOException, SmackParsingException, ParseException;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright © 2014-2019 Florian Schmaus
* Copyright © 2014-2021 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -117,7 +117,7 @@ public static Object parseWithIntrospection(Class<?> objectClass,
* @param type the type of the property.
* @param value the encode String value to decode.
* @return the String value decoded into the specified type.
* @throws ClassNotFoundException
* @throws ClassNotFoundException if the provided class was not found.
*/
private static Object decode(Class<?> type, String value) throws ClassNotFoundException {
String name = type.getName();
Expand Down

0 comments on commit 288834f

Please sign in to comment.