Skip to content

Commit a721e0c

Browse files
committed
working (and hopefully solved) the specific problem that an era < 0 crashes the app. It is to be solved in ASAPJava anyway.
1 parent 8c3ce55 commit a721e0c

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

app/src/main/java/net/sharksystem/asap/android/ASAPServiceMessage.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class ASAPServiceMessage {
2424
private byte[] message = null;
2525
private String readableName;
2626
private boolean persistent;
27+
private boolean eraNotSet = false;
2728

2829
public String toString() {
2930
StringBuilder sb = new StringBuilder();
@@ -285,8 +286,12 @@ private void parseASAPMessage(Bundle msgData, boolean mandatory) throws ASAPExce
285286
private void parseEra(Bundle msgData, boolean mandatory) throws ASAPException {
286287
this.era = msgData.getInt(ASAPServiceMethods.ERA_TAG, ERA_TAG_NOT_SET);
287288

288-
if(mandatory && this.era == ERA_TAG_NOT_SET) {
289-
throw new ASAPException("era must be set");
289+
if(this.era == ERA_TAG_NOT_SET) {
290+
if(mandatory) throw new ASAPException("era must be set");
291+
else {
292+
this.eraNotSet = true;
293+
this.era = 0;
294+
}
290295
}
291296
}
292297

@@ -334,8 +339,15 @@ public boolean isRecipientsListSet() {
334339

335340
public CharSequence getURI() { return this.uri; }
336341

337-
public int getEra() { return this.era; }
338-
public boolean isEraSet() { return this.era != ERA_TAG_NOT_SET; }
342+
public int getEra() {
343+
if(this.era < 0) {
344+
Log.d(this.getLogStart(), "era must not be negative - replace with 0: " + this.era);
345+
this.eraNotSet = true;
346+
this.era = 0;
347+
}
348+
return this.era;
349+
}
350+
public boolean isEraSet() { return !this.eraNotSet; }
339351

340352
public byte[] getASAPMessage() { return this.message; }
341353
public boolean isASAPMessageSet() { return this.message != null && this.message.length > 0;}

app/src/main/java/net/sharksystem/asap/android/apps/ASAPApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,6 @@ public void setOnlinePeersList(List<CharSequence> peerList) {
465465
}
466466

467467
private String getLogStart() {
468-
return this.getClass().getSimpleName();
468+
return "ASAPApplication";
469469
}
470470
}

0 commit comments

Comments
 (0)