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

EObytes$EOslice fails when input is wrong #3749

Open
yegor256 opened this issue Dec 23, 2024 · 2 comments
Open

EObytes$EOslice fails when input is wrong #3749

yegor256 opened this issue Dec 23, 2024 · 2 comments

Comments

@yegor256
Copy link
Member

I see this:

  ⇢ 1022) o.e.PhDefault#take():160
  ⇢ 1023) o.e.AtomSafe#lambda():49
  ⇢ 1024) E.E.EObytes$EOslice#lambda():81
  ⇢ 1025) j.u.Arrays#copyOfRange():3853
  ⇢ 1026) j.l.System#arraycopy():-2
  ⇢ 1027) "arraycopy: length -7 is negative"

However, we have all the proper checks there. Why don't they detect incorrect input?

@yegor256
Copy link
Member Author

@jacks-sam1010 Latta, you are is almost there! This is how the method should look:

    @Override
    public Phi lambda() {
        final byte[] array = new Dataized(this.take(Attr.RHO)).take();
        final int start = Expect.at(this, "start")
            .that(phi -> new Dataized(phi).asNumber())
            .otherwise("must be a number")
            .must(number -> number % 1 == 0)
            .that(Double::intValue)
            .otherwise("must be an integer")
            .must(integer -> integer >= 0)
            .otherwise("must be a positive integer")
            .must(integer -> integer < array.length)
            .otherwise(String.format("must be lt %d", array.length))
            .it();
        final int length = Expect.at(this, "len")
            .that(phi -> new Dataized(phi).asNumber())
            .otherwise("must be a number")
            .must(number -> number % 1 == 0)
            .that(Double::intValue)
            .otherwise("must be an integer")
            .must(integer -> integer >= 0)
            .otherwise("must be a positive integer")
            .must(integer -> start + integer <= array.length)
            .otherwise(String.format("must be lte %d minus %d", array.length, start))
            .it();
        return new Data.ToPhi(
            Arrays.copyOfRange(
                array,
                start, start + length
            )
        );
    }

However, with these changes 12 tests fail. Let's fix them.

yegor256 added a commit that referenced this issue Dec 28, 2024
yegor256 added a commit that referenced this issue Dec 28, 2024
@yegor256 yegor256 mentioned this issue Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
@yegor256 and others