Skip to content

Commit 24e0c41

Browse files
Copilotcommjoen
andcommitted
Revert to Java 23 in pom.xml and update all code to use Java 23 syntax features
Co-authored-by: commjoen <[email protected]>
1 parent d46c169 commit 24e0c41

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
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>17</java.version>
60+
<java.version>23</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>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ public List<Difficulty> difficulties() {
9696
}
9797

9898
public boolean isFirstChallenge(ChallengeDefinition challengeDefinition) {
99-
return challengeDefinition.equals(definitions.challenges().get(0));
99+
return challengeDefinition.equals(definitions.challenges().getFirst());
100100
}
101101

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

107107
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().get(0));
112+
return extractor.apply(challengeDefinition.sources().getFirst());
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
@@ -97,7 +97,7 @@ 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).get(0).spoiler();
100+
return challenges.getChallenge(challengeDefinition).getFirst().spoiler();
101101
};
102102

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

src/main/java/org/owasp/wrongsecrets/challenges/docker/Challenge14.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public String getAnswer() {
4545

4646
try (InputStream inputStream = Files.newInputStream(Paths.get(filePath))) {
4747
database = SimpleDatabase.load(creds, inputStream);
48-
return database.findEntries("alibaba").get(0).getPassword();
48+
return database.findEntries("alibaba").getFirst().getPassword();
4949
} catch (Exception | Error e) {
5050
log.error("Exception or Error with Challenge 14", e);
5151
try (InputStream inputStream =
5252
Files.newInputStream(Paths.get("src/test/resources/alibabacreds.kdbx"))) {
5353
database = SimpleDatabase.load(creds, inputStream);
54-
return database.findEntries("alibaba").get(0).getPassword();
54+
return database.findEntries("alibaba").getFirst().getPassword();
5555
} catch (Exception | Error e2) {
5656
log.error("Exception or Error with Challenge 14 second time", e2);
5757
return defaultKeepassValue;

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().get(0);
39+
var randomChallenge = challenges.getChallengeDefinitions().getFirst();
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().get(0);
47+
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
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().get(0);
55+
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
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().get(0);
45+
var firstChallenge = challenges.getChallengeDefinitions().getFirst();
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).get(0);
54+
var challenge9 = challenges.getChallenge(challenge9Definition).getFirst();
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: 6 additions & 5 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().get(0));
19+
challengeDefinitionsConfiguration.challenges().getFirst());
2020

2121
assertThat(navigation.previous()).isEmpty();
2222
}
@@ -27,16 +27,17 @@ void navigateNextWhenOnLastChallenge() {
2727
var navigation =
2828
new Navigator(
2929
challenges,
30-
challenges.get(challenges.size() - 1));
30+
challenges.getLast());
3131

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

3535
@Test
3636
void navigatePreviousAndNextOnSecondChallenge() {
37-
var first = challengeDefinitionsConfiguration.challenges().get(0);
38-
var second = challengeDefinitionsConfiguration.challenges().get(1);
39-
var third = challengeDefinitionsConfiguration.challenges().get(2);
37+
var challenges = challengeDefinitionsConfiguration.challenges();
38+
var first = challenges.getFirst();
39+
var second = challenges.get(1);
40+
var third = challenges.get(2);
4041

4142
var navigation = new Navigator(challengeDefinitionsConfiguration.challenges(), second);
4243

0 commit comments

Comments
 (0)