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