Skip to content

Commit 2f557ac

Browse files
authored
Merge pull request #3799 from mapfish/Remove_deprecated_test_code
Migrate Java 5 - 17 code to Java 21 Fix math related bugs.
2 parents b04d92b + f8e941b commit 2f557ac

File tree

223 files changed

+1109
-1449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+1109
-1449
lines changed

.github/workflows/main.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ jobs:
3131
with:
3232
fetch-depth: 0
3333

34+
- uses: actions/setup-java@v5
35+
with:
36+
distribution: 'temurin'
37+
java-version: '21'
38+
3439
- uses: actions/setup-python@v6
3540
with:
3641
python-version: '3.13'

core/src/main/java/org/mapfish/print/FontTools.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.io.BufferedReader;
55
import java.io.IOException;
66
import java.io.InputStreamReader;
7+
import java.nio.charset.StandardCharsets;
78
import java.util.ArrayList;
89
import java.util.Collections;
910
import java.util.HashSet;
@@ -62,7 +63,7 @@ public static List<FontConfigDescription> listFontConfigFonts(final String famil
6263
String[] commands = {"fc-list", "-b", family};
6364
Process process = Runtime.getRuntime().exec(commands);
6465

65-
inputStreamReader = new InputStreamReader(process.getInputStream(), "utf-8");
66+
inputStreamReader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8);
6667
stdInput = new BufferedReader(inputStreamReader);
6768
String inputLine;
6869
FontConfigDescription description = null;

core/src/main/java/org/mapfish/print/SvgUtil.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ private static class BufferedImageTranscoder extends ImageTranscoder {
4242

4343
@Override
4444
public BufferedImage createImage(final int w, final int h) {
45-
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
46-
return bi;
45+
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
4746
}
4847

4948
@Override

core/src/main/java/org/mapfish/print/URIUtils.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.net.URL;
1010
import java.net.URLDecoder;
1111
import java.net.URLEncoder;
12+
import java.nio.charset.StandardCharsets;
1213
import java.util.Collection;
1314
import java.util.Map;
1415
import java.util.Set;
@@ -54,13 +55,8 @@ public static Multimap<String, String> getParameters(final String rawQuery) {
5455
key = pair;
5556
value = "";
5657
} else {
57-
58-
try {
59-
key = URLDecoder.decode(pair.substring(0, pos), "UTF-8");
60-
value = URLDecoder.decode(pair.substring(pos + 1), "UTF-8");
61-
} catch (UnsupportedEncodingException e) {
62-
throw new PrintException("Failed to get parameters for query " + rawQuery, e);
63-
}
58+
key = URLDecoder.decode(pair.substring(0, pos), StandardCharsets.UTF_8);
59+
value = URLDecoder.decode(pair.substring(pos + 1), StandardCharsets.UTF_8);
6460
}
6561

6662
result.put(key, value);
@@ -214,7 +210,7 @@ public static URI setQueryParams(
214210
final URI initialUri, final Multimap<String, String> queryParams) {
215211
StringBuilder queryString = new StringBuilder();
216212
for (Map.Entry<String, String> entry : queryParams.entries()) {
217-
if (queryString.length() > 0) {
213+
if (!queryString.isEmpty()) {
218214
queryString.append("&");
219215
}
220216
queryString.append(entry.getKey()).append("=").append(entry.getValue());

core/src/main/java/org/mapfish/print/attribute/StringArrayAttribute.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/** An attribute that can contain an array of strings. [[examples=verboseExample]] */
44
public class StringArrayAttribute extends PrimitiveAttribute<String[]> {
55
/** Constructor. */
6-
@SuppressWarnings("unchecked")
76
public StringArrayAttribute() {
87
super(String[].class);
98
}

core/src/main/java/org/mapfish/print/attribute/StringAttribute.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public final void setMaxLength(final int maxLength) {
3939

4040
@Override
4141
public final void validateValue(final Object value) {
42-
if (this.maxLength >= 0 && value instanceof String) {
43-
String text = (String) value;
42+
if (this.maxLength >= 0 && value instanceof String text) {
4443
if (text.length() > this.maxLength) {
4544
throw new IllegalArgumentException(
4645
"text contains more than " + this.maxLength + " characters");

core/src/main/java/org/mapfish/print/attribute/map/CenterScaleMapBounds.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import static org.mapfish.print.Constants.PDF_DPI;
44

5+
import com.google.common.annotations.VisibleForTesting;
56
import java.awt.Rectangle;
7+
import java.util.Objects;
68
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
79
import org.geotools.api.referencing.operation.TransformException;
810
import org.geotools.geometry.Position2D;
@@ -179,12 +181,21 @@ private ReferencedEnvelope computeGeodeticBBox(
179181
}
180182
}
181183

182-
private double rollLongitude(final double x) {
183-
return x - (((int) (x + Math.signum(x) * 180)) / 360) * 360.0;
184+
@VisibleForTesting
185+
double rollLongitude(final double x) {
186+
return modulo(x + 180, 360.0) - 180;
184187
}
185188

186-
private double rollLatitude(final double y) {
187-
return y - (((int) (y + Math.signum(y) * 90)) / 180) * 180.0;
189+
private static double modulo(final double a, final double b) {
190+
return b - ((-a % b) + b) % b;
191+
}
192+
193+
@VisibleForTesting
194+
double rollLatitude(final double y) {
195+
if (y > 90 || y < -90) {
196+
throw new IllegalArgumentException("Latitude must be between -90 and 90");
197+
}
198+
return y;
188199
}
189200

190201
@Override
@@ -201,10 +212,10 @@ public boolean equals(final Object o) {
201212

202213
final CenterScaleMapBounds that = (CenterScaleMapBounds) o;
203214

204-
if (this.center != null ? !this.center.equals(that.center) : that.center != null) {
215+
if (!Objects.equals(this.center, that.center)) {
205216
return false;
206217
}
207-
return this.scale != null ? this.scale.equals(that.scale) : that.scale == null;
218+
return Objects.equals(this.scale, that.scale);
208219
}
209220

210221
@Override

core/src/main/java/org/mapfish/print/attribute/map/MapAttribute.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public final class MapAttribute extends GenericMapAttribute {
3030
ZoomLevelSnapStrategy.CLOSEST_LOWER_SCALE_ON_TIE;
3131
private static final boolean DEFAULT_SNAP_GEODETIC = false;
3232

33-
@SuppressWarnings("unchecked")
3433
@Override
3534
public Class<MapAttributeValues> getValueType() {
3635
return MapAttributeValues.class;

core/src/main/java/org/mapfish/print/attribute/map/MapfishMapContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ public AffineTransform getTransform() {
301301
final AffineTransform transform = AffineTransform.getTranslateInstance(0.0, 0.0);
302302
// move to the center of the original map rectangle (this is the actual
303303
// size of the graphic)
304-
transform.translate(this.mapSize.width / 2, this.mapSize.height / 2);
304+
transform.translate(this.mapSize.width / 2.0, this.mapSize.height / 2.0);
305305

306306
// then rotate around this center
307307
transform.rotate(this.rotation);
308308

309309
// then move to an artificial origin (0,0) which might be outside the actual
310310
// painting area. this origin still keeps the center of the original map area
311311
// at the center of the rotated map area.
312-
transform.translate(-rotatedMapSize.width / 2, -rotatedMapSize.height / 2);
312+
transform.translate(-rotatedMapSize.width / 2.0, -rotatedMapSize.height / 2.0);
313313

314314
return transform;
315315
}

core/src/main/java/org/mapfish/print/attribute/map/OverviewMapAttribute.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public void setStyle(final String style) {
4141
this.style = style;
4242
}
4343

44-
@SuppressWarnings("unchecked")
4544
@Override
4645
public Class<OverviewMapAttributeValues> getValueType() {
4746
return OverviewMapAttributeValues.class;

0 commit comments

Comments
 (0)