Skip to content

Commit 3295034

Browse files
committed
Merge branch '5.2.x' into master
2 parents b50ad1b + 49356b2 commit 3295034

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

spring-core/src/main/java/org/springframework/util/SimpleIdGenerator.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,25 +20,20 @@
2020
import java.util.concurrent.atomic.AtomicLong;
2121

2222
/**
23-
* A simple {@link IdGenerator} that starts at 1 and increments by 1 with each call.
23+
* A simple {@link IdGenerator} that starts at 1, increments up to
24+
* {@link Long#MAX_VALUE}, and then rolls over.
2425
*
2526
* @author Rossen Stoyanchev
2627
* @since 4.1.5
2728
*/
2829
public class SimpleIdGenerator implements IdGenerator {
2930

30-
private final AtomicLong mostSigBits = new AtomicLong(0);
31-
3231
private final AtomicLong leastSigBits = new AtomicLong(0);
3332

3433

3534
@Override
3635
public UUID generateId() {
37-
long leastSigBits = this.leastSigBits.incrementAndGet();
38-
if (leastSigBits == 0) {
39-
this.mostSigBits.incrementAndGet();
40-
}
41-
return new UUID(this.mostSigBits.get(), leastSigBits);
36+
return new UUID(0, this.leastSigBits.incrementAndGet());
4237
}
4338

4439
}

spring-webflux/src/test/java/org/springframework/web/reactive/resource/PathResourceResolverTests.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,16 +17,17 @@
1717

1818
import java.io.IOException;
1919
import java.time.Duration;
20+
import java.util.Collections;
2021
import java.util.List;
2122

2223
import org.junit.jupiter.api.Test;
24+
import reactor.core.publisher.Mono;
2325

2426
import org.springframework.core.io.ClassPathResource;
2527
import org.springframework.core.io.FileUrlResource;
2628
import org.springframework.core.io.Resource;
2729
import org.springframework.core.io.UrlResource;
2830

29-
import static java.util.Collections.singletonList;
3031
import static org.assertj.core.api.Assertions.assertThat;
3132
import static org.assertj.core.api.Assertions.fail;
3233

@@ -46,7 +47,7 @@ public class PathResourceResolverTests {
4647
public void resolveFromClasspath() throws IOException {
4748
Resource location = new ClassPathResource("test/", PathResourceResolver.class);
4849
String path = "bar.css";
49-
List<Resource> locations = singletonList(location);
50+
List<Resource> locations = Collections.singletonList(location);
5051
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
5152

5253
assertThat(actual).isEqualTo(location.createRelative(path));
@@ -56,7 +57,7 @@ public void resolveFromClasspath() throws IOException {
5657
public void resolveFromClasspathRoot() {
5758
Resource location = new ClassPathResource("/");
5859
String path = "org/springframework/web/reactive/resource/test/bar.css";
59-
List<Resource> locations = singletonList(location);
60+
List<Resource> locations = Collections.singletonList(location);
6061
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
6162

6263
assertThat(actual).isNotNull();
@@ -71,7 +72,7 @@ public void resolveWithEncodedPath() throws IOException {
7172

7273
private void testWithEncodedPath(Resource location) throws IOException {
7374
String path = "foo%20foo.txt";
74-
List<Resource> locations = singletonList(location);
75+
List<Resource> locations = Collections.singletonList(location);
7576
Resource actual = this.resolver.resolveResource(null, path, locations, null).block(TIMEOUT);
7677

7778
assertThat(actual).isNotNull();
@@ -98,7 +99,7 @@ public void checkResource() throws IOException {
9899
}
99100

100101
private void testCheckResource(Resource location, String requestPath) throws IOException {
101-
List<Resource> locations = singletonList(location);
102+
List<Resource> locations = Collections.singletonList(location);
102103
Resource actual = this.resolver.resolveResource(null, requestPath, locations, null).block(TIMEOUT);
103104
if (!location.createRelative(requestPath).exists() && !requestPath.contains(":")) {
104105
fail(requestPath + " doesn't actually exist as a relative path");
@@ -122,17 +123,20 @@ public void checkResourceWithAllowedLocations() {
122123

123124
Resource location = getResource("main.css");
124125
String actual = this.resolver.resolveUrlPath("../testalternatepath/bar.css",
125-
singletonList(location), null).block(TIMEOUT);
126+
Collections.singletonList(location), null).block(TIMEOUT);
126127

127128
assertThat(actual).isEqualTo("../testalternatepath/bar.css");
128129
}
129130

130131
@Test // SPR-12624
131132
public void checkRelativeLocation() throws Exception {
132-
String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
133-
Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
134-
List<Resource> locations = singletonList(location);
135-
assertThat(this.resolver.resolveResource(null, "main.css", locations, null).block(TIMEOUT)).isNotNull();
133+
String location= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
134+
location = location.replace("/test/org/springframework","/test/org/../org/springframework");
135+
136+
Mono<Resource> resourceMono = this.resolver.resolveResource(
137+
null, "main.css", Collections.singletonList(new UrlResource(location)), null);
138+
139+
assertThat(resourceMono.block(TIMEOUT)).isNotNull();
136140
}
137141

138142
@Test // SPR-12747
@@ -145,7 +149,7 @@ public void checkFileLocation() throws Exception {
145149
public void resolvePathRootResource() {
146150
Resource webjarsLocation = new ClassPathResource("/META-INF/resources/webjars/", PathResourceResolver.class);
147151
String path = this.resolver.resolveUrlPathInternal(
148-
"", singletonList(webjarsLocation), null).block(TIMEOUT);
152+
"", Collections.singletonList(webjarsLocation), null).block(TIMEOUT);
149153

150154
assertThat(path).isNull();
151155
}

spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PathResourceResolverTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -125,10 +125,13 @@ public void checkServletContextResource() throws Exception {
125125

126126
@Test // SPR-12624
127127
public void checkRelativeLocation() throws Exception {
128-
String locationUrl= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
129-
Resource location = new UrlResource(locationUrl.replace("/springframework","/../org/springframework"));
128+
String location= new UrlResource(getClass().getResource("./test/")).getURL().toExternalForm();
129+
location = location.replace("/test/org/springframework","/test/org/../org/springframework");
130130

131-
assertThat(this.resolver.resolveResource(null, "main.css", Collections.singletonList(location), null)).isNotNull();
131+
Resource actual = this.resolver.resolveResource(
132+
null, "main.css", Collections.singletonList(new UrlResource(location)), null);
133+
134+
assertThat(actual).isNotNull();
132135
}
133136

134137
@Test // SPR-12747

0 commit comments

Comments
 (0)