Skip to content

Unsafe casting in getItems() method #7

@Touchie771

Description

@Touchie771

Issue Description

The getItems() method in Menu.java performs an unsafe cast from Collections.unmodifiableSet() to HashSet<SlotItem>. This could cause ClassCastException at runtime.

Location

Menu.java line 148

Current Code

public HashSet<SlotItem> getItems() {
    return (HashSet<SlotItem>) Collections.unmodifiableSet(this.items);
}

Suggested Fix

Change the return type to Set<SlotItem>:

public Set<SlotItem> getItems() {
    return Collections.unmodifiableSet(this.items);
}

Impact

This is a bug waiting to happen - users expecting a mutable HashSet might get unexpected runtime errors when trying to use HashSet-specific methods.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions