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

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

Open
Kormic1 opened this issue Aug 4, 2024 · 0 comments
Open

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

Kormic1 opened this issue Aug 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@Kormic1
Copy link

Kormic1 commented Aug 4, 2024

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.

@sovdeeth sovdeeth added the bug Something isn't working label Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants