Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip checking binary files for possible JUnit dependencies #886

Closed
wants to merge 2 commits into from

Conversation

schlosna
Copy link
Contributor

@schlosna schlosna commented Sep 24, 2019

Before this PR

The checkJUnitDependencies task would attempt to scan all files in a source set, including binary files such as src/test/resources/server_keystore.jks, which would lead to a java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1 (see
https://circleci.com/gh/palantir/tritium/4234 & palantir/tritium#439 ):

java.io.UncheckedIOException: java.nio.charset.MalformedInputException: Input length = 1
    at java.base/java.nio.file.FileChannelLinesSpliterator.readLine(FileChannelLinesSpliterator.java:173)
    at java.base/java.nio.file.FileChannelLinesSpliterator.tryAdvance(FileChannelLinesSpliterator.java:101)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:230)
    at java.base/java.util.stream.MatchOps$MatchOp.evaluateSequential(MatchOps.java:196)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.anyMatch(ReferencePipeline.java:528)
    at com.palantir.baseline.tasks.CheckJUnitDependencies.fileContainsSubstring(CheckJUnitDependencies.java:153)
    at com.palantir.baseline.tasks.CheckJUnitDependencies.lambda$sourceSetMentionsJUnit5Api$5(CheckJUnitDependencies.java:147)
    at org.gradle.util.CollectionUtils.filter(CollectionUtils.java:154)
    at org.gradle.api.internal.file.AbstractFileCollection$5.getFiles(AbstractFileCollection.java:245)
    at org.gradle.api.internal.file.AbstractFileCollection.isEmpty(AbstractFileCollection.java:194)
    at org.gradle.api.internal.file.CompositeFileCollection.isEmpty(CompositeFileCollection.java:99)
    at com.palantir.baseline.tasks.CheckJUnitDependencies.sourceSetMentionsJUnit5Api(CheckJUnitDependencies.java:148)
    at com.palantir.baseline.tasks.CheckJUnitDependencies.validateSourceSet(CheckJUnitDependencies.java:72)
    at com.palantir.baseline.tasks.CheckJUnitDependencies.lambda$validateDependencies$0(CheckJUnitDependencies.java:61)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at com.palantir.baseline.tasks.CheckJUnitDependencies.validateDependencies(CheckJUnitDependencies.java:46)
    ...snip gradle stuff...
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.base/java.nio.charset.CoderResult.throwException(CoderResult.java:274)
    at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
    at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
    at java.base/java.io.BufferedReader.fill(BufferedReader.java:161)
    at java.base/java.io.BufferedReader.readLine(BufferedReader.java:326)
    at java.base/java.io.BufferedReader.readLine(BufferedReader.java:392)
    at java.base/java.nio.file.FileChannelLinesSpliterator.readLine(FileChannelLinesSpliterator.java:171)
    ... 117 more

After this PR

==COMMIT_MSG==
Treat MalformedInputException as binary files that are not necessary to
scan for old JUnit dependencies.

Rethrow any non-IOExeception (such as UncheckedIOException wrapping
MalformedInputException) with more useful error message indicating a
file could not be scanned (e.g. src/test/resources/server_keystore.jks).
==COMMIT_MSG==

Possible downsides?

This method of attempting to exclude non-source files may potentially have false-negatives of not flagging old JUnit dependencies in a source file if it were to trigger a MalformedInputException while reading (e.g. if the source file was not UTF-8 but instead UTF-16 or UCS-2 per https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.1)

Treat MalformedInputException as binary files that are not necessary to
scan for old JUnit dependencies.

Rethrow any non-IOExeception (such as UncheckedIOException wrapping
MalformedInputException) with more useful error message indicating a
file could not be scanned (e.g. src/test/resources/server_keystore.jks).
@schlosna schlosna requested a review from a team as a code owner September 24, 2019 19:02
@changelog-app
Copy link

changelog-app bot commented Sep 24, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Treat MalformedInputException as binary files that are not necessary to
scan for old JUnit dependencies.

Rethrow any non-IOExeception (such as UncheckedIOException wrapping
MalformedInputException) with more useful error message indicating a
file could not be scanned (e.g. ).

Check the box to generate changelog(s)

  • Generate changelog entry

@ferozco
Copy link
Contributor

ferozco commented Sep 24, 2019

@schlosna I've merged and released #885 which also solves the same problem.

@schlosna schlosna closed this Sep 24, 2019
@schlosna schlosna deleted the ds/junit-check-binary-files branch September 24, 2019 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants