-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-64390] make FieldUtils behave as it used to (#5105)
Co-authored-by: Jesse Glick <jglick@cloudbees.com>
- Loading branch information
Showing
3 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
core/src/test/java/org/acegisecurity/util/FieldUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.acegisecurity.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@SuppressWarnings("deprecation") | ||
public class FieldUtilsTest { | ||
|
||
@Issue("JENKINS-64390") | ||
@Test | ||
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_InnerClass() throws Exception { | ||
InnerClassWithPublicFinalField sut = new InnerClassWithPublicFinalField(); | ||
FieldUtils.setProtectedFieldValue("myField", sut, "test"); | ||
assertEquals(sut.getMyField(), "original"); | ||
} | ||
|
||
@Test | ||
@Issue("JENKINS-64390") | ||
public void setProtectedFieldValue_Should_fail_silently_to_set_public_final_fields_in_OuterClass() throws Exception { | ||
OuterClassWithPublicFinalField sut = new OuterClassWithPublicFinalField(); | ||
FieldUtils.setProtectedFieldValue("myField", sut, "test"); | ||
assertEquals(sut.getMyField(), "original"); | ||
} | ||
|
||
@Test | ||
public void setProtectedFieldValue_Should_Succeed() throws Exception { | ||
InnerClassWithProtectedField sut = new InnerClassWithProtectedField(); | ||
FieldUtils.setProtectedFieldValue("myProtectedField", sut, "test"); | ||
assertEquals(sut.getMyNonFinalField(), "test"); | ||
} | ||
|
||
@Test | ||
public void setNonExistingField_Should_Fail() throws Exception { | ||
InnerClassWithProtectedField sut = new InnerClassWithProtectedField(); | ||
assertThrows(Exception.class, () -> FieldUtils.setProtectedFieldValue("bogus", sut, "whatever")); | ||
} | ||
|
||
class InnerClassWithPublicFinalField { | ||
|
||
public final String myField = "original"; | ||
|
||
public String getMyField() { | ||
return myField; | ||
} | ||
|
||
} | ||
|
||
public class InnerClassWithProtectedField { | ||
|
||
protected String myProtectedField = "original"; | ||
|
||
public String getMyNonFinalField() { | ||
return myProtectedField; | ||
} | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/src/test/java/org/acegisecurity/util/OuterClassWithPublicFinalField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.acegisecurity.util; | ||
|
||
public class OuterClassWithPublicFinalField { | ||
|
||
public final String myField = "original"; | ||
|
||
public String getMyField() { | ||
return myField; | ||
} | ||
} |