Skip to content

Commit

Permalink
Fix encoding error messages when generated on Java 8 (#1181 fixes #1081)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg committed Apr 22, 2022
2 parents d59fdb2 + 40df41d commit 38f7305
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Expand Up @@ -13,7 +13,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Added
* Added support for enabling ktlint experimental ruleset. ([#1145](https://github.com/diffplug/spotless/pull/1168))
### Fixed
* 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))
* 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))
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))

## [2.24.2] - 2022-04-06
### Fixed
Expand Down
14 changes: 10 additions & 4 deletions lib/src/main/java/com/diffplug/spotless/EncodingErrorMsg.java
@@ -1,5 +1,5 @@
/*
* Copyright 2016 DiffPlug
* Copyright 2016-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/
package com.diffplug.spotless;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -115,8 +116,8 @@ private static void addIfAvailable(Collection<Charset> charsets, String name) {
}

private void appendExample(Charset charset, boolean must) {
byteBuf.clear();
charBuf.clear();
java8fix(byteBuf).clear();
java8fix(charBuf).clear();

CharsetDecoder decoder = charset.newDecoder();
if (!must) {
Expand All @@ -134,7 +135,7 @@ private void appendExample(Charset charset, boolean must) {
.onUnmappableCharacter(CodingErrorAction.REPLACE)
.decode(byteBuf, charBuf, true);
}
charBuf.flip();
java8fix(charBuf).flip();

int start = Math.max(unrepresentable - CONTEXT, 0);
int end = Math.min(charBuf.limit(), unrepresentable + CONTEXT + 1);
Expand All @@ -146,4 +147,9 @@ private void appendExample(Charset charset, boolean must) {
message.append(" <- ");
message.append(charset.name());
}

/** Fixes https://jira.mongodb.org/browse/JAVA-2559, as reported in https://github.com/diffplug/spotless/issues/1081 */
private static Buffer java8fix(Buffer b) {
return b;
}
}
1 change: 1 addition & 0 deletions plugin-gradle/CHANGES.md
Expand Up @@ -9,6 +9,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
### Fixed
* 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))
* All tasks (including helper tasks) are now part of the `verification` group. (fixes [#1050](https://github.com/diffplug/spotless/issues/1050))
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))
### Changed
- 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))
- 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).
Expand Down
3 changes: 2 additions & 1 deletion plugin-maven/CHANGES.md
Expand Up @@ -4,7 +4,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Fixed
* 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))
* 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))
* Error messages for unexpected file encoding now works on Java 8. (fixes [#1081](https://github.com/diffplug/spotless/issues/1081))

## [2.22.1] - 2022-04-06
### Fixed
Expand Down

0 comments on commit 38f7305

Please sign in to comment.