Skip to content

Commit d76c744

Browse files
Copilotcommjoen
andcommitted
Fix Java compatibility issues - replace Java 21+ List methods with Java 17 compatible alternatives
Co-authored-by: commjoen <[email protected]>
1 parent b181902 commit d76c744

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

src/main/java/org/owasp/wrongsecrets/Challenges.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ public boolean isFirstChallenge(ChallengeDefinition challengeDefinition) {
100100
}
101101

102102
public boolean isLastChallenge(ChallengeDefinition challengeDefinition) {
103-
return challengeDefinition.equals(definitions.challenges().getLast());
103+
var challenges = definitions.challenges();
104+
return challengeDefinition.equals(challenges.get(challenges.size() - 1));
104105
}
105106

106107
public List<ChallengeDefinition> getChallengeDefinitions() {

src/main/java/org/owasp/wrongsecrets/challenges/ChallengeUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private String documentation(Function<ChallengeSource, String> extractor) {
109109
return challengeDefinition.source(runtimeEnvironment).map(extractor).orElse("");
110110
} else {
111111
// We cannot run the challenge but showing documentation should still be possible
112-
return extractor.apply(challengeDefinition.sources().getFirst());
112+
return extractor.apply(challengeDefinition.sources().get(0));
113113
}
114114
}
115115

src/main/java/org/owasp/wrongsecrets/challenges/ChallengesController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public String spoiler(@PathVariable("short-name") String shortName, Model model)
9797
Supplier<Spoiler> spoilerFromRandomChallenge =
9898
() -> {
9999
var challengeDefinition = findByShortName(shortName);
100-
return challenges.getChallenge(challengeDefinition).getFirst().spoiler();
100+
var challengeList = challenges.getChallenge(challengeDefinition);
101+
return challengeList.get(0).spoiler();
101102
};
102103

103104
// We always want to show the spoiler even if we run in a non-supported environment

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFClientModeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ class ChallengesControllerCTFClientModeTest {
3636

3737
@Test
3838
void shouldNotSpoilWhenInCTFMode() throws Exception {
39-
var randomChallenge = challenges.getChallengeDefinitions().getFirst();
39+
var randomChallenge = challenges.getChallengeDefinitions().get(0);
4040
mvc.perform(get("/spoil/%s".formatted(randomChallenge.name().shortName())))
4141
.andExpect(status().isOk())
4242
.andExpect(content().string(containsString("Spoils are disabled in CTF mode")));
4343
}
4444

4545
@Test
4646
void shouldNotSpoilWhenInCTFModeEvenWhenChallengeUnsupported() throws Exception {
47-
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
47+
var firstChallenge = challenges.getChallengeDefinitions().get(0);
4848
mvc.perform(get("/spoil/%s".formatted(firstChallenge.name().shortName())))
4949
.andExpect(status().isOk())
5050
.andExpect(content().string(containsString("Spoils are disabled in CTF mode")));
5151
}
5252

5353
@Test
5454
void challenge0SshouldSShowTheAddressRightAnswersNeedToBeSubmittedTo() throws Exception {
55-
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
55+
var firstChallenge = challenges.getChallengeDefinitions().get(0);
5656
mvc.perform(get("/challenge/%s".formatted(firstChallenge.name().shortName())))
5757
.andExpect(status().isOk())
5858
.andExpect(content().string(containsString("https://www.google.nl")));

src/test/java/org/owasp/wrongsecrets/ctftests/ChallengesControllerCTFModeWithPresetCloudValuesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ChallengesControllerCTFModeWithPresetCloudValuesTest {
4242

4343
@Test
4444
void shouldNotSpoilWhenInCTFMode() throws Exception {
45-
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
45+
var firstChallenge = challenges.getChallengeDefinitions().get(0);
4646
mvc.perform(get("/spoil/%s".formatted(firstChallenge.name().shortName())))
4747
.andExpect(status().isOk())
4848
.andExpect(content().string(containsString("Spoils are disabled in CTF mode")));
@@ -51,7 +51,7 @@ void shouldNotSpoilWhenInCTFMode() throws Exception {
5151
@Test
5252
void shouldShowFlagWhenRespondingWithSuccessInCTFModeChallenge9() throws Exception {
5353
var challenge9Definition = challenges.findByShortName("challenge-9").orElseThrow();
54-
var challenge9 = challenges.getChallenge(challenge9Definition).getFirst();
54+
var challenge9 = challenges.getChallenge(challenge9Definition).get(0);
5555
var spoil = challenge9.spoiler().solution();
5656
mvc.perform(
5757
post("/challenge/%s".formatted(challenge9Definition.name().shortName()))

src/test/java/org/owasp/wrongsecrets/definitions/NavigationTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,25 @@ void navigatePreviousWhenOnFirstChallenge() {
1616
var navigation =
1717
new Navigator(
1818
challengeDefinitionsConfiguration.challenges(),
19-
challengeDefinitionsConfiguration.challenges().getFirst());
19+
challengeDefinitionsConfiguration.challenges().get(0));
2020

2121
assertThat(navigation.previous()).isEmpty();
2222
}
2323

2424
@Test
2525
void navigateNextWhenOnLastChallenge() {
26+
var challenges = challengeDefinitionsConfiguration.challenges();
2627
var navigation =
2728
new Navigator(
28-
challengeDefinitionsConfiguration.challenges(),
29-
challengeDefinitionsConfiguration.challenges().getLast());
29+
challenges,
30+
challenges.get(challenges.size() - 1));
3031

3132
assertThat(navigation.next()).isEmpty();
3233
}
3334

3435
@Test
3536
void navigatePreviousAndNextOnSecondChallenge() {
36-
var first = challengeDefinitionsConfiguration.challenges().getFirst();
37+
var first = challengeDefinitionsConfiguration.challenges().get(0);
3738
var second = challengeDefinitionsConfiguration.challenges().get(1);
3839
var third = challengeDefinitionsConfiguration.challenges().get(2);
3940

0 commit comments

Comments
 (0)