Bug fixed - nullpointer exception result.all(), result.one()

This commit is contained in:
Ahmed Salah Tawfik Ibrahim 2023-11-22 19:40:29 +01:00
parent 6cf162bb91
commit 9ea2895833
1 changed files with 13 additions and 11 deletions

View File

@ -2088,7 +2088,8 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
//if there are no settings for this user create an entry and put all of them at true
if (result.all().isEmpty()) {
List<Row> results = result.all();
if (results.isEmpty()) {
_log.info("Userid " + userid + " settings not found, initiating its preferences...");
HashMap<NotificationType, NotificationChannelType[]> toCreate = new HashMap<NotificationType, NotificationChannelType[]>();
@ -2108,7 +2109,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
else {
_log.trace("Notification preferences Found for " + userid);
for (Row row: result.all()){
for (Row row: results){
String[] channels = row.getString(PREFERENCE).split(",");
if (channels != null && channels.length == 1 && channels[0].toString().equals("") ) { //it is empty, preference is set to no notification at all
toReturn.put(getNotificationType(row.getString(TYPE)), new NotificationChannelType[0]);
@ -2190,11 +2191,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(UUID.fromString(commentId)));
if (result.all().isEmpty()) {
toReturn = readCommentFromRow(result.one());
if (toReturn==null) {
throw new CommentIDNotFoundException("The requested commentId: " + commentId + " is not existing");
}
toReturn = readCommentFromRow(result.one());
} catch (Exception e){
e.printStackTrace();
}
@ -2284,9 +2285,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
result = session.execute(stmtFind.bind());
if (!result.all().isEmpty()){
result.all().parallelStream().forEach( row->{
List<Row> results = result.all();
if (!results.isEmpty()){
results.parallelStream().forEach( row->{
if(row.getString(USER_ID).equals(userid)){
try{
Comment c = readCommentById(row.getUuid(COMMENT_ID).toString());
@ -3065,10 +3066,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(UUID.fromString(inviteid)));
if (result.one() == null) {
toReturn = readAInviteFromRow(result.one());
if (toReturn == null) {
throw new InviteStatusNotFoundException("The requested inviteid: " + inviteid + " is not existing");
}
toReturn = readAInviteFromRow(result.one());
//toReturn = readAInviteFromRow(result.all().get(0));
} catch (Exception e){
e.printStackTrace();
@ -3637,7 +3639,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.selectFrom(VRE_TIMELINE_POSTS).column(VRE_ID).all()
.build());
try {
result = session.execute(stmtFind.getQuery());
result = session.execute(stmtFind.bind());
} catch (Exception e){
e.printStackTrace();