Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bookmarks): Permit references to tags from previous invocations #7

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

olivergondza
Copy link
Owner

No description provided.

src/main/java/com/github/olivergondza/saxeed/Tag.java Outdated Show resolved Hide resolved
Comment on lines 68 to 78
private TagImpl(TagImpl parent, TagName name) {
this.parent = parent;
this.name = Objects.requireNonNull(name);
this.attrs = null; // No SAX attrs, setting attributes right away
// No SAX attrs, setting attributes right away
this.attrs = null;
this.attributes = new LinkedHashMap<>();
this.namespaces = null;
this.generated = true;
this.bookmark = initBookmark();
init(parent);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor TagImpl(TagImpl parent, TagName name) initializes the attributes and namespaces fields to empty collections or null. This can lead to potential NullPointerException issues if these fields are accessed without null checks elsewhere in the code. Consider initializing these fields to empty collections to avoid such issues.

Comment on lines 83 to 92
public TagImpl(TagImpl parent, TagName name, Attributes attrs, Map<String, String> namespaces) {
this.parent = parent;
this.name = Objects.requireNonNull(name);
this.attrs = Objects.requireNonNull(attrs);
// Create defensive copy in either case
this.namespaces = namespaces.isEmpty() ? null : new LinkedHashMap<>(namespaces);
this.generated = false;
this.bookmark = initBookmark();
init(parent);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor TagImpl(TagImpl parent, TagName name, Attributes attrs, Map<String, String> namespaces) does not perform a null check on the namespaces parameter before calling namespaces.isEmpty(). This can lead to a NullPointerException if namespaces is null. Consider adding a null check for the namespaces parameter before using it.

Comment on lines +50 to +68
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

BookmarkImpl bookmark = (BookmarkImpl) o;

// If either is omitted, they are not equal. This is to prevent that omitted bookmark would match real tag based
// on value clash.
if (omitted || bookmark.omitted) {
return false;
}

return Objects.equals(value, bookmark.value);
}

@Override
public int hashCode() {
return Objects.hash(value, omitted);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The equals and hashCode methods are not consistent. The equals method considers both value and omitted fields, while the hashCode method only considers the value field. This inconsistency can lead to unexpected behavior when instances of BookmarkImpl are used in collections that rely on these methods.

Recommendation: Ensure that both equals and hashCode methods consider the same fields. Either include omitted in the hashCode method or exclude it from the equals method.

@olivergondza olivergondza merged commit fe14d24 into main Jun 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant