Skip to content

Commit 38f7305

Browse files
authored
Fix encoding error messages when generated on Java 8 (#1181 fixes #1081)
2 parents d59fdb2 + 40df41d commit 38f7305

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1313
### Added
1414
* Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168))
1515
### Fixed
16-
* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170))
16+
* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170))
17+
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))
1718

1819
## [2.24.2] - 2022-04-06
1920
### Fixed

lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 DiffPlug
2+
* Copyright 2016-2022 DiffPlug
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.
@@ -15,6 +15,7 @@
1515
*/
1616
package com.diffplug.spotless;
1717

18+
import java.nio.Buffer;
1819
import java.nio.ByteBuffer;
1920
import java.nio.CharBuffer;
2021
import java.nio.charset.Charset;
@@ -115,8 +116,8 @@ private static void addIfAvailable(Collection<Charset> charsets, String name) {
115116
}
116117

117118
private void appendExample(Charset charset, boolean must) {
118-
byteBuf.clear();
119-
charBuf.clear();
119+
java8fix(byteBuf).clear();
120+
java8fix(charBuf).clear();
120121

121122
CharsetDecoder decoder = charset.newDecoder();
122123
if (!must) {
@@ -134,7 +135,7 @@ private void appendExample(Charset charset, boolean must) {
134135
.onUnmappableCharacter(CodingErrorAction.REPLACE)
135136
.decode(byteBuf, charBuf, true);
136137
}
137-
charBuf.flip();
138+
java8fix(charBuf).flip();
138139

139140
int start = Math.max(unrepresentable - CONTEXT, 0);
140141
int end = Math.min(charBuf.limit(), unrepresentable + CONTEXT + 1);
@@ -146,4 +147,9 @@ private void appendExample(Charset charset, boolean must) {
146147
message.append(" <- ");
147148
message.append(charset.name());
148149
}
150+
151+
/** Fixes https://jira.mongodb.org/browse/JAVA-2559, as reported in https://github.com/diffplug/spotless/issues/1081 */
152+
private static Buffer java8fix(Buffer b) {
153+
return b;
154+
}
149155
}

plugin-gradle/CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
99
### Fixed
1010
* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170))
1111
* All tasks (including helper tasks) are now part of the `verification` group. (fixes [#1050](https://github.com/diffplug/spotless/issues/1050))
12+
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))
1213
### Changed
1314
- Spotless now applies the `base` plugin to make sure that Spotless always has a `check` task to hook into. ([#1179](https://github.com/diffplug/spotless/pull/1179), fixes [#1164](https://github.com/diffplug/spotless/pull/1164), reverts [#1014](https://github.com/diffplug/spotless/pull/1014))
1415
- Spotless used to work this way, we stopped applying base starting with version [`6.0.3` (released Dec 2021)](https://github.com/diffplug/spotless/blob/main/plugin-gradle/CHANGES.md#603---2021-12-06) in order to play nicely with a now-outdated Android template, but not applying `base` causes more problems than it fixes (see [#1164](https://github.com/diffplug/spotless/pull/1164) for a good example).

plugin-maven/CHANGES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
44

55
## [Unreleased]
66
### Fixed
7-
* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`) ([#1170](https://github.com/diffplug/spotless/issues/1170))
7+
* Fixed support for Python Black's new version reporting, and bumped default version to latest (`19.10b0` -> `22.3.0`). ([#1170](https://github.com/diffplug/spotless/issues/1170))
8+
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))
89

910
## [2.22.1] - 2022-04-06
1011
### Fixed

0 commit comments

Comments
 (0)