1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-25 03:57:58 +01:00

Generic Exception replaced with Type Specific Exceptions.

'parseAndProcessStanza()' throws generic Exceptions.
Since there are plenty of exceptions that should not be
catched by smack, it's better to throw Type Specific Exceptions.
This Commit is was in response to SMACK-839.
This commit is contained in:
adiaholic 2019-05-19 13:31:17 +05:30
parent f7762c5db7
commit f91044657f
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);