GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot mock this class: class java.io.InputStream with Java 13 · Issue #1827 · mockito/mockito

Cannot mock this class: class java.io.InputStream with Java 13 #1827

New issue
Copy link
New issue
Copy link
Closed
Closed
Cannot mock this class: class java.io.InputStream with Java 13#1827
Copy link

Description

@adamretter
adamretter
opened on Nov 24, 2019
Issue body actions

## Versions

  • Mockito: 3.1.0
  • JDK: 13.0.1+9
  • OS: macOS 10.13
  • XCode: 10.1-19

Code causing the error

InputStream in = mock(InputStream.class);

Error:

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.015 s <<< FAILURE! - in uk.gov.nationalarchives.droid.core.interfaces.archive.ZipEntryRequestFactoryTest
[ERROR] testNewZipRequest(uk.gov.nationalarchives.droid.core.interfaces.archive.ZipEntryRequestFactoryTest)  Time elapsed: 0.005 s  <<< ERROR!
org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class java.io.InputStream.
If you're not sure why you're getting this error, please report to the mailing list.
Java               : 13
JVM vendor name    : Oracle Corporation
JVM vendor version : 13.0.1+9
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 13.0.1+9
JVM info           : mixed mode, sharing
OS name            : Mac OS X
OS version         : 10.13.6
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, class java.io.InputStream, interface java.lang.AutoCloseable, interface java.io.Closeable]
	at uk.gov.nationalarchives.droid.core.interfaces.archive.ZipEntryRequestFactoryTest.testNewZipRequest(ZipEntryRequestFactoryTest.java:70)
Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, class java.io.InputStream, interface java.lang.AutoCloseable, interface java.io.Closeable]
	at uk.gov.nationalarchives.droid.core.interfaces.archive.ZipEntryRequestFactoryTest.testNewZipRequest(ZipEntryRequestFactoryTest.java:70)
Caused by: java.lang.IllegalStateException: 
Byte Buddy could not instrument all classes within the mock's type hierarchy
This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
 - Compiled by older versions of scalac
 - Classes that are part of the Android distribution
	at uk.gov.nationalarchives.droid.core.interfaces.archive.ZipEntryRequestFactoryTest.testNewZipRequest(ZipEntryRequestFactoryTest.java:70)
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 57
	at uk.gov.nationalarchives.droid.core.interfaces.archive.ZipEntryRequestFactoryTest.testNewZipRequest(ZipEntryRequestFactoryTest.java:70)
Reacted by dianhenglau, Jakub Spręga and Dmitry Timofeev

Activity

  1. adamretter
    added 3 commits that reference this issue on Nov 24, 2019

    Use JDK 12 on MacOS Travis CI to workaround JDK 13 incompatibility, s…

    18c8a81

    fixup! Use JDK 12 on MacOS Travis CI to workaround JDK 13 incompatibi…

    2cd9646

    Use JDK 10 on MacOS Travis CI to workaround JDK 13 incompatibility, s…

    b285381
  2. dmitry-timofeev commented on Nov 26, 2019

    @dmitry-timofeev
    dmitry-timofeev
    on Nov 26, 2019
    Contributor
    More actions

    We had same issues with Java 13. I just overrode Mockito Byte Buddy dependency to a newer version (1.10.3), and it solved inline mock failures in our tests.

    Submitted the upgrade in Mockito itself: #1828

  3. TimvdLippe commented on Nov 26, 2019

    @TimvdLippe
    TimvdLippe
    on Nov 26, 2019
    Contributor
    More actions

    Please do not mock Inputstream, but create a real example with fake data instead. That said, we will update Byte Buddy to be compatible with Java 13.

  4. TimvdLippe
    added a commit that references this issue on Nov 28, 2019

    Add annotation to mark a type as DoNotMock

    b740f99
  5. dmitry-timofeev commented on Nov 29, 2019

    @dmitry-timofeev
    dmitry-timofeev
    on Nov 29, 2019
    Contributor
    More actions

    Thank you @TimvdLippe ! Would it be possible please to push this release to Maven Central? Creating inline mocks of any classes compiled with javac 13 does not work, not just platform classes like InputStream, so I think this release can be considered 'notable' according to the release policy.

  6. TimvdLippe commented on Nov 29, 2019

    @TimvdLippe
    TimvdLippe
    on Nov 29, 2019
    Contributor
    More actions

    It is being released: d7c5ac4

  7. TimvdLippe
    closed this as completedon Nov 29, 2019
  8. dmitry-timofeev commented on Nov 29, 2019

    @dmitry-timofeev
    dmitry-timofeev
    on Nov 29, 2019
    Contributor
    More actions

    Wonderful, thanks!

  9. adamretter commented on Nov 29, 2019

    @adamretter
    adamretter
    on Nov 29, 2019
    Author
    More actions

    Thanks everyone for the quick response :-)

  10. TimvdLippe
    added a commit that references this issue on Nov 19, 2021

    Add annotation to mark a type as DoNotMock (#1833)

    ebc1685
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.