WorldEdit

WorldEdit

43M Downloads

BlockArrayClipboard#getRegion does not respect its documentation

bristermitten opened this issue ยท 2 comments

commented

WorldEdit Version

7.2.10

Platform Version

git-Paper-386

Confirmations

  • I am using the most recent Minecraft release.
  • I am using a version of WorldEdit compatible with my Minecraft version.
  • I am using the latest or recommended version of my platform software.
  • I am NOT using a hybrid server, e.g. a server that combines Bukkit and Forge. Examples include Arclight, Mohist, and Cardboard.
  • I am NOT using a fork of WorldEdit, such as FastAsyncWorldEdit (FAWE) or AsyncWorldEdit (AWE)

Bug Description

According to the documentation for Clipboard#getRegion

Implementations should return a copy of the region.

This is not true for BlockArrayClipboard, which currently defines getRegion as

@Override
public Region getRegion() {
    return region;
}

The returned region is not a copy, and therefore mutations directly affect the clipboard. This can lead to difficult to trace bugs when working with clipboards in the API

Either this is intended behaviour, in which case the documentation should be updated to make it clear that clone() should be used, or the implementation of BlockArrayClipboard#getRegion should be changed to match the documentation.

Expected Behavior

The returned Region should be a copy of the actual region field, therefore not mutating the clipboard.

Reproduction Steps

  1. Get a Clipboard object through the API, which has an implementation of type BlockArrayClipboard
  2. Mutate the value returned by Clipboard#getRegion, e.g with Region#shift

Anything Else?

No response

commented

Technically, "should" does not require that implementations do so. It's a strong recommendation (RFC 2119). It might be a good idea for us to change this anyways, but it is not a bug.

commented

Added in d7b3c4c