Skip to content

Commit bb021c3

Browse files
Copilotcommjoen
andcommitted
Fix Java 17 compatibility issues - Update to Java 17 and fix getFirst/getLast usage
Co-authored-by: commjoen <[email protected]>
1 parent 4ea30e0 commit bb021c3

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
<gcp.sdk.version>7.2.0</gcp.sdk.version>
5858
<github.button.version>2.14.1</github.button.version>
5959
<io.netty.version>4.1.118.Final</io.netty.version>
60-
<java.version>23</java.version>
60+
<java.version>17</java.version>
6161
<jquery.version>3.7.1</jquery.version>
6262
<jruby.version>10.0.2.0</jruby.version>
6363
<lombok.version>1.18.38</lombok.version>
6464
<maven-compiler-plugin.version>3.14.0</maven-compiler-plugin.version>
6565
<maven.compiler.proc>full</maven.compiler.proc>
66-
<maven.compiler.target>23</maven.compiler.target>
66+
<maven.compiler.target>17</maven.compiler.target>
6767
<spring.cloud-version>2025.0.0</spring.cloud-version>
6868
<spring.security.version>6.2.3</spring.security.version>
6969
<system-stubs-jupiter.version>2.1.8</system-stubs-jupiter.version>
@@ -539,8 +539,8 @@
539539
<artifactId>maven-compiler-plugin</artifactId>
540540
<version>${maven-compiler-plugin.version}</version>
541541
<configuration>
542-
<source>23</source>
543-
<target>23</target>
542+
<source>17</source>
543+
<target>17</target>
544544
</configuration>
545545
</plugin>
546546
<plugin>

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public String spoiler(@PathVariable("short-name") String shortName, Model model)
102102
Supplier<Spoiler> spoilerFromRandomChallenge =
103103
() -> {
104104
var challengeDefinition = findByShortName(shortName);
105-
return challenges.getChallenge(challengeDefinition).getFirst().spoiler();
105+
return challenges.getChallenge(challengeDefinition).get(0).spoiler();
106106
};
107107

108108
// 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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
}
@@ -26,14 +26,14 @@ void navigateNextWhenOnLastChallenge() {
2626
var navigation =
2727
new Navigator(
2828
challengeDefinitionsConfiguration.challenges(),
29-
challengeDefinitionsConfiguration.challenges().getLast());
29+
challengeDefinitionsConfiguration.challenges().get(challengeDefinitionsConfiguration.challenges().size() - 1));
3030

3131
assertThat(navigation.next()).isEmpty();
3232
}
3333

3434
@Test
3535
void navigatePreviousAndNextOnSecondChallenge() {
36-
var first = challengeDefinitionsConfiguration.challenges().getFirst();
36+
var first = challengeDefinitionsConfiguration.challenges().get(0);
3737
var second = challengeDefinitionsConfiguration.challenges().get(1);
3838
var third = challengeDefinitionsConfiguration.challenges().get(2);
3939

0 commit comments

Comments
 (0)