Skip to content

Original array isn't manipulated when passed to a method #119

Open
@Kormic1

Description

Describe the bug
When passing an array to a method, the original array isn't manipulated. Seems like the copy of an array is used instead.

To reproduce
Code using SecureRandom#nextBytes method:

command /test:
	trigger:
		# Tried with different algorithms and with SecureRandom.getInstanceStrong(), same issue
		set {_rng} to SecureRandom.getInstance("SHA1PRNG", "SUN")
		set {_salt} to new byte[4]
		send {_salt}
		{_rng}.nextBytes({_salt})
		send {_salt}

Result:

[13:14:12 INFO]: [0, 0, 0, 0]
[13:14:12 INFO]: [0, 0, 0, 0]

Code using Arrays.fill method:

command /test:
    trigger:
        set {_array} to new byte[4]
        send {_array}
        Arrays.fill({_array}, 5)
        send {_array}

Result:

[13:15:12 INFO]: [0, 0, 0, 0]
[13:15:12 INFO]: [0, 0, 0, 0]

Expected behavior
Both examples above should result in arrays being filled with numbers (random numbers in the first example). I ran analogous code in Java (same JDK version) and it worked flawlessly.
To confirm the issue, one person (to whom I am grateful) created a small test JAR with the following code:

public class Main {
    private static final int[] arr = new int[2];

    public static int[] get() {
        return arr;
    }
}

and a script with the code below:

command /test:
    trigger:
        set {_array} to Main.get()
        broadcast {_array}
        Arrays.fill({_array}, 5)
        broadcast Main.get()

Result:

[22:34:59 INFO]: [0, 0]
[22:34:59 INFO]: [0, 0]

Screenshots
None.

Server information

  • skript-reflect: 2.5.1
  • Skript: 2.9.1
  • Paper: 1.21-111
  • Minecraft: 1.21
  • Java: 22.0.2
  • OS: Windows 10

Additional context
I stumbled upon this issue when I was fiddling with SecureRandom class to generate salt for hashing passwords.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions