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

Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option #1168

Open
3 tasks done
fctg-kandasas opened this issue Sep 25, 2023 · 8 comments

Comments

@fctg-kandasas
Copy link

fctg-kandasas commented Sep 25, 2023

Just be aware about usual MockK support pattern.
Tickets are checked from time to time, replied, discussed, labeled, e.t.c.
But real fixes are applied in a month-two month period in a bunch.
If you think this is unacceptable, go on, join the project, change the world.

Please remove sections wisely

Below information is actually needed to make all the process of fixing faster.
Choose main points. Don't blindly follow this as a set of rules.
Don't waste much time. Usually, the main thing is to have a good reproducible minimal code.

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

Kotest should run with mockk 1.13.8

Current Behavior

What is the current behavior?

Failure Information (for bugs)

Compile and Runtime error
Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. step 1 - Upgrade mockk library to 1.13.8 in Kotlin based JVM 1.8 project
  2. step 2
  3. started getting compile error "Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option"

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • MockK version: 1.13.8
  • OS: Windows
  • Kotlin version: 1.8.21
  • JDK version: 1.8
  • JUnit version:
  • Type of test: unit test OR android instrumented test
    Kotest

Failure Logs

Cannot inline bytecode built with JVM target 11 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option

Please include any relevant log snippets or files here.

Stack trace

// -----------------------[ YOUR STACK STARTS HERE ] -----------------------

// -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------

Minimal reproducible code (the gist of this issue)

We are using maven to build the project.

// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
@igorwojda
Copy link

igorwojda commented Sep 27, 2023

I was able to deep dive into this. I have created a simple script that verifies the JVM target of a few mockk artifacts (others need to be checked as well). It checks if artifacts are compiled with the correct byte code:

mockk-core-jvm-1.13.7.jar - is compiled to bytecode 52 (Java 8) ✅
mockk-core-jvm-1.13.8.jar - is compiled to bytecode 55 (Java 11) ❌

Here is the full run
image

Steps to Reproduce

  1. Download artifacts https://repo1.maven.org/maven2/io/mockk/mockk-core/ (mockk-core-jvm-1.13.7.jar mockk-core-jvm-1.13.8.jar)
  2. In the same directory this script in the check_bytecode_version.py file in the same directory as artifacts and run it python3 check_bytecode_version.py
import sys
import subprocess
import os
import tempfile
import shutil

def get_bytecode_version(class_file):
    result = subprocess.run(["javap", "-verbose", class_file], capture_output=True, text=True)
    for line in result.stdout.splitlines():
        if "major version" in line:
            return line.split(":")[-1].strip()

def main(file_path):
    # Java 8 == bytecode version 52.0 (defined in the local.javalibrary.gradle.kts)
    desired_java_version = "8"
    desired_bytecode_version = "52"

    if os.path.exists(file_path):
        print(f"Verify if all classes in {file_path} are compiled to bytecode {desired_bytecode_version} (Java {desired_java_version})")
    else:
        print("File not found:", file_path)

    

    # Create a temporary directory
    temp_dir = "./temp"

    try:
        # Unzip the jar file to the temporary directory
        subprocess.run(["unzip", "-qq", file_path, "-d", temp_dir], check=True)

        # Walk the directory to find all .class files
        for root, _, files in os.walk(temp_dir):
            for file in files:
                print("file", file)
                if file.endswith(".class"):
                    file_path = os.path.join(root, file)
                    version = get_bytecode_version(file_path)
                    if version != desired_bytecode_version:
                        print(f"❌ ERROR {file_path} has incorrect bytecode version {version}")
                        sys.exit(1)
                    else:
                        print(f"✅ SUCCESS {file_path} has correct bytecode version {version}")
        
        print(f"✅✅✅ All classed in {file_path} have correct bytecode")
        print()
    finally:
        # Clean up the temporary directory
        aaa = True
        shutil.rmtree(temp_dir)

if __name__ == "__main__":    
    main("mockk-1.13.7.jar")
    main("mockk-1.13.8.jar")
    main("mockk-core-1.13.7.jar")
    main("mockk-core-1.13.8.jar")
    main("mockk-core-jvm-1.13.7.jar")
    main("mockk-core-jvm-1.13.8.jar")

It looks like this PR may have caused the issue #1056

Here is the failing PR upgrading mockk v1.13.7 -> v1.13.8
LemonAppDev/konsist#640

BTW
Here is the updated version of the script that I am using in Konsist to verify if the build produces an artifact with the desired bytecode version
https://github.com/LemonAppDev/konsist/blob/develop/scripts/check_bytecode_version.py
and a GitHub action that runs this script https://github.com/LemonAppDev/konsist/blob/develop/.github/workflows/check.yml
May be worth adding to mockk after fixing this issue to avoid this issue in the future.

@Antimonit
Copy link

Fixed via #1161

@frapontillo
Copy link

Any updates on when we will get a new release for this?

@MMasterson
Copy link

Any updates on this release?

@mobile-pablo
Copy link

mobile-pablo commented Nov 18, 2023

Same issue occurs for me. Whats current status of issue ? cc : @odrotbohm

@andrademv
Copy link

hey guys! issue was solved in 1.13.7, but is back in 1.13.8

@alexandrupele
Copy link

Also getting it in 1.13.8

oheger added a commit to oheger/WifiControl that referenced this issue Jan 1, 2024
KoTest: 5.6.2 -> 5.8.0
mockk: 1.13.5 -> 1.13.7
Robolectric: 4.10.3 -> 4.11.1

Note that due to [1], the most recent version of mockk cannot be used.

[1]: mockk/mockk#1168

Signed-off-by: Oliver Heger <oliver.heger@oliver-heger.de>
oheger added a commit to oheger/WifiControl that referenced this issue Jan 1, 2024
KoTest: 5.6.2 -> 5.8.0
mockk: 1.13.5 -> 1.13.7
Robolectric: 4.10.3 -> 4.11.1

Note that due to [1], the most recent version of mockk cannot be used.

[1]: mockk/mockk#1168

Signed-off-by: Oliver Heger <oliver.heger@oliver-heger.de>
@dotrothschild
Copy link

Android studio downgrade works: I use it in Android Studio Kotlin, indeed, downgrade to 1.13.7

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

No branches or pull requests

9 participants