-
Notifications
You must be signed in to change notification settings - Fork 106
Open
Labels
bug 🐞Something isn't workingSomething isn't working
Description
Description:
When getting value from Map data structure, it can return null value(undefined in TS) for not having the key.
But I found out some functions not checking it properly.
For example, getPrevCreatedAt function in RGATreeList is implemented as below:
public getPrevCreatedAt(createdAt: TimeTicket): TimeTicket {
let node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
do {
node = node!.getPrev()!;
} while (this.dummyHead !== node && node.isRemoved());
return node.getValue().getCreatedAt();
}It is not checking the case that nodeMapByCreatedAt doesn't contain the key and node is assigned null value.
Thus, it might be better to fix it like this:
public getPrevCreatedAt(createdAt: TimeTicket): TimeTicket {
let node = this.nodeMapByCreatedAt.get(createdAt.toIDString());
if (!node) {
// throw error or exception
}
do {
node = node!.getPrev()!;
} while (this.dummyHead !== node && node.isRemoved());
return node.getValue().getCreatedAt();
}I only looked through RGATreeList, so it might be necessary to check other parts of the code as well.
Why:
hackerwins
Metadata
Metadata
Assignees
Labels
bug 🐞Something isn't workingSomething isn't working