Merge pull request #303 from adiaholic/SMACK-839

Generic Exception replaced with Type Specific Exceptions.
This commit is contained in:
Florian Schmaus 2019-05-20 09:44:04 +02:00 committed by GitHub
commit e8d9aed4be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -1251,7 +1251,7 @@ public abstract class AbstractXMPPConnection implements XMPPConnection {
try { try {
stanza = PacketParserUtils.parseStanza(parser, incomingStreamXmlEnvironment); stanza = PacketParserUtils.parseStanza(parser, incomingStreamXmlEnvironment);
} }
catch (Exception e) { catch (XmlPullParserException | SmackParsingException | IOException e) {
CharSequence content = PacketParserUtils.parseContentDepth(parser, CharSequence content = PacketParserUtils.parseContentDepth(parser,
parserDepth); parserDepth);
UnparseableStanza message = new UnparseableStanza(content, e); UnparseableStanza message = new UnparseableStanza(content, e);

View File

@ -55,6 +55,7 @@ import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException; import org.jivesoftware.smack.xml.XmlPullParserException;
import org.jxmpp.jid.Jid; import org.jxmpp.jid.Jid;
import org.jxmpp.stringprep.XmppStringprepException;
/** /**
* Utility class that helps to parse packets. Any parsing packets method that must be shared * Utility class that helps to parse packets. Any parsing packets method that must be shared
@ -89,7 +90,7 @@ public class PacketParserUtils {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <S extends Stanza> S parseStanza(String stanza) throws Exception { public static <S extends Stanza> S parseStanza(String stanza) throws XmlPullParserException, SmackParsingException, IOException {
return (S) parseStanza(getParserFor(stanza), null); return (S) parseStanza(getParserFor(stanza), null);
} }
@ -101,9 +102,11 @@ public class PacketParserUtils {
* @param parser * @param parser
* @param outerXmlEnvironment the outer XML environment (optional). * @param outerXmlEnvironment the outer XML environment (optional).
* @return a stanza which is either a Message, IQ or Presence. * @return a stanza which is either a Message, IQ or Presence.
* @throws Exception * @throws XmlPullParserException
* @throws SmackParsingException
* @throws IOException
*/ */
public static Stanza parseStanza(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws Exception { public static Stanza parseStanza(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, SmackParsingException, IOException {
ParserUtils.assertAtStartTag(parser); ParserUtils.assertAtStartTag(parser);
final String name = parser.getName(); final String name = parser.getName();
switch (name) { switch (name) {
@ -508,9 +511,12 @@ public class PacketParserUtils {
* @param parser the XML parser, positioned at the start of an IQ packet. * @param parser the XML parser, positioned at the start of an IQ packet.
* @param outerXmlEnvironment the outer XML environment (optional). * @param outerXmlEnvironment the outer XML environment (optional).
* @return an IQ object. * @return an IQ object.
* @throws Exception * @throws XmlPullParserException
* @throws XmppStringprepException
* @throws IOException
* @throws SmackParsingException
*/ */
public static IQ parseIQ(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws Exception { public static IQ parseIQ(XmlPullParser parser, XmlEnvironment outerXmlEnvironment) throws XmlPullParserException, XmppStringprepException, IOException, SmackParsingException {
ParserUtils.assertAtStartTag(parser); ParserUtils.assertAtStartTag(parser);
final int initialDepth = parser.getDepth(); final int initialDepth = parser.getDepth();
XmlEnvironment iqXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment); XmlEnvironment iqXmlEnvironment = XmlEnvironment.from(parser, outerXmlEnvironment);