Fix OlmException cast issue
- OlmException class extends now from IOException - update corresponding serializing unit tests - update
This commit is contained in:
parent
0d3c1a2a46
commit
7a0d7cc36d
6 changed files with 46 additions and 60 deletions
|
@ -196,13 +196,12 @@ public class OlmGroupSessionTest {
|
|||
FileInputStream fileInput = context.openFileInput(FILE_NAME_SERIAL_OUT_SESSION);
|
||||
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
|
||||
outboundGroupSessionSerial = (OlmOutboundGroupSession) objectInput.readObject();
|
||||
assertNotNull(outboundGroupSessionSerial);
|
||||
objectInput.close();
|
||||
|
||||
// get sessions keys
|
||||
String sessionKeyRef = outboundGroupSessionRef.sessionKey();
|
||||
String sessionKeySerial = outboundGroupSessionSerial.sessionKey();
|
||||
|
||||
// session keys sanity check
|
||||
assertFalse(TextUtils.isEmpty(sessionKeyRef));
|
||||
assertFalse(TextUtils.isEmpty(sessionKeySerial));
|
||||
|
||||
|
@ -212,8 +211,6 @@ public class OlmGroupSessionTest {
|
|||
// get sessions IDs
|
||||
String sessionIdRef = outboundGroupSessionRef.sessionIdentifier();
|
||||
String sessionIdSerial = outboundGroupSessionSerial.sessionIdentifier();
|
||||
|
||||
// session ID sanity check
|
||||
assertFalse(TextUtils.isEmpty(sessionIdRef));
|
||||
assertFalse(TextUtils.isEmpty(sessionIdSerial));
|
||||
|
||||
|
@ -222,21 +219,16 @@ public class OlmGroupSessionTest {
|
|||
|
||||
outboundGroupSessionRef.releaseSession();
|
||||
outboundGroupSessionSerial.releaseSession();
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage());
|
||||
}
|
||||
/*catch (OlmException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception OlmException Msg==" + e.getMessage());
|
||||
}*/
|
||||
catch (Exception e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception Msg==" + e.getMessage());
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
|
||||
} catch (OlmException e) {
|
||||
Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception OlmException Msg==" + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception IOException Msg==" + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "## test14SerializeOutboundSession(): Exception Msg==" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,17 +269,16 @@ public class OlmGroupSessionTest {
|
|||
objectOutput.close();
|
||||
|
||||
// deserialize session
|
||||
FileInputStream fileInput = context.openFileInput(FILE_NAME_SERIAL_OUT_SESSION);
|
||||
FileInputStream fileInput = context.openFileInput(FILE_NAME_SERIAL_IN_SESSION);
|
||||
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
|
||||
bobInboundGroupSessionSerial = (OlmInboundGroupSession)objectInput.readObject();
|
||||
assertNotNull(bobInboundGroupSessionSerial);
|
||||
objectInput.close();
|
||||
|
||||
// get sessions IDs
|
||||
String aliceSessionId = aliceOutboundGroupSession.sessionIdentifier();
|
||||
String sessionIdRef = bobInboundGroupSessionRef.sessionIdentifier();
|
||||
String sessionIdSerial = bobInboundGroupSessionSerial.sessionIdentifier();
|
||||
|
||||
// session ID sanity check
|
||||
assertFalse(TextUtils.isEmpty(aliceSessionId));
|
||||
assertFalse(TextUtils.isEmpty(sessionIdRef));
|
||||
assertFalse(TextUtils.isEmpty(sessionIdSerial));
|
||||
|
@ -295,18 +286,20 @@ public class OlmGroupSessionTest {
|
|||
// session IDs comparison
|
||||
assertTrue(aliceSessionId.equals(sessionIdSerial));
|
||||
assertTrue(sessionIdRef.equals(sessionIdSerial));
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
|
||||
}
|
||||
catch (IOException e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception Msg==" + e.getMessage());
|
||||
|
||||
aliceOutboundGroupSession.releaseSession();
|
||||
bobInboundGroupSessionRef.releaseSession();
|
||||
bobInboundGroupSessionSerial.releaseSession();
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception FileNotFoundException Msg=="+e.getMessage());
|
||||
} catch (ClassNotFoundException e) {
|
||||
Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception ClassNotFoundException Msg==" + e.getMessage());
|
||||
} catch (OlmException e) {
|
||||
Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception OlmException Msg==" + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception IOException Msg==" + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "## test15SerializeInboundSession(): Exception Msg==" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,9 +69,8 @@ public class OlmAccount implements Serializable {
|
|||
* Kick off the serialization mechanism.
|
||||
* @param aOutStream output stream for serializing
|
||||
* @throws IOException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException, OlmException {
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||
aOutStream.defaultWriteObject();
|
||||
|
||||
// generate serialization key
|
||||
|
@ -94,9 +93,8 @@ public class OlmAccount implements Serializable {
|
|||
* @param aInStream input stream
|
||||
* @throws IOException exception
|
||||
* @throws ClassNotFoundException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException, OlmException {
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||
aInStream.defaultReadObject();
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
package org.matrix.olm;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Exception class to identify specific Olm SDK exceptions.
|
||||
*/
|
||||
public class OlmException extends Exception {
|
||||
public class OlmException extends IOException {
|
||||
// exception codes
|
||||
public static final int EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION = 0;
|
||||
public static final int EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION = 1;
|
||||
|
@ -37,18 +39,17 @@ public class OlmException extends Exception {
|
|||
public static final int EXCEPTION_CODE_INBOUND_GROUP_SESSION_DESERIALIZATION = 13;
|
||||
|
||||
// exception human readable messages
|
||||
public static final String EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION = "failed to create a new outbound group Session";
|
||||
public static final String EXCEPTION_MSG_NEW_INBOUND_GROUP_SESSION = "failed to create a new inbound group Session";
|
||||
public static final String EXCEPTION_MSG_INIT_OUTBOUND_GROUP_SESSION = "failed to initialize a new outbound group Session";
|
||||
public static final String EXCEPTION_MSG_INIT_INBOUND_GROUP_SESSION = "failed to initialize a new inbound group Session";
|
||||
public static final String EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION = "createNewSession() failed";
|
||||
public static final String EXCEPTION_MSG_NEW_INBOUND_GROUP_SESSION = "createNewSession() failed";
|
||||
public static final String EXCEPTION_MSG_INIT_OUTBOUND_GROUP_SESSION = "initOutboundGroupSession() failed";
|
||||
public static final String EXCEPTION_MSG_INIT_INBOUND_GROUP_SESSION = " initInboundGroupSessionWithSessionKey() failed";
|
||||
public static final String EXCEPTION_MSG_INIT_NEW_ACCOUNT_DESERIALIZATION = "initNewAccount() failure";
|
||||
public static final String EXCEPTION_MSG_INIT_ACCOUNT_DESERIALIZATION = "initWithSerializedData() failure";
|
||||
public static final String EXCEPTION_MSG_INVALID_PARAMS_DESERIALIZATION = "invalid de-serialized parameters";
|
||||
public static final String EXCEPTION_MSG_INIT_ACCOUNT_CREATION = "Account constructor failure";
|
||||
public static final String EXCEPTION_MSG_INIT_SESSION_CREATION = "Session constructor failure";
|
||||
public static final String EXCEPTION_MSG_INIT_ACCOUNT_CREATION = "initNewAccount() failed";
|
||||
public static final String EXCEPTION_MSG_INIT_SESSION_CREATION = "initNewSession() failed";
|
||||
|
||||
/** exception code to be taken from: {@link #EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION} {@link #EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION}
|
||||
* {@link #EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION} {@link #EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION}**/
|
||||
/** exception code to be taken from: {@link #EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION}, {@link #EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION},
|
||||
* {@link #EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION}, {@link #EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION}..**/
|
||||
private final int mCode;
|
||||
|
||||
/** Human readable message description **/
|
||||
|
|
|
@ -137,9 +137,8 @@ public class OlmInboundGroupSession implements Serializable {
|
|||
* Kick off the serialization mechanism.
|
||||
* @param aOutStream output stream for serializing
|
||||
* @throws IOException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException, OlmException {
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||
aOutStream.defaultWriteObject();
|
||||
|
||||
// generate serialization key
|
||||
|
@ -162,9 +161,8 @@ public class OlmInboundGroupSession implements Serializable {
|
|||
* @param aInStream input stream
|
||||
* @throws IOException exception
|
||||
* @throws ClassNotFoundException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException, OlmException {
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||
aInStream.defaultReadObject();
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
|
||||
|
|
|
@ -63,9 +63,8 @@ public class OlmOutboundGroupSession implements Serializable {
|
|||
* Kick off the serialization mechanism.
|
||||
* @param aOutStream output stream for serializing
|
||||
* @throws IOException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException, OlmException {
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||
aOutStream.defaultWriteObject();
|
||||
|
||||
// generate serialization key
|
||||
|
@ -88,9 +87,8 @@ public class OlmOutboundGroupSession implements Serializable {
|
|||
* @param aInStream input stream
|
||||
* @throws IOException exception
|
||||
* @throws ClassNotFoundException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException, OlmException {
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||
aInStream.defaultReadObject();
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
|
||||
|
|
|
@ -52,9 +52,8 @@ public class OlmSession implements Serializable {
|
|||
* Kick off the serialization mechanism.
|
||||
* @param aOutStream output stream for serializing
|
||||
* @throws IOException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException, OlmException {
|
||||
private void writeObject(ObjectOutputStream aOutStream) throws IOException {
|
||||
aOutStream.defaultWriteObject();
|
||||
|
||||
// generate serialization key
|
||||
|
@ -77,9 +76,8 @@ public class OlmSession implements Serializable {
|
|||
* @param aInStream input stream
|
||||
* @throws IOException exception
|
||||
* @throws ClassNotFoundException exception
|
||||
* @throws OlmException exception
|
||||
*/
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException, OlmException {
|
||||
private void readObject(ObjectInputStream aInStream) throws IOException, ClassNotFoundException {
|
||||
aInStream.defaultReadObject();
|
||||
StringBuffer errorMsg = new StringBuffer();
|
||||
|
||||
|
|
Loading…
Reference in a new issue