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

Support java 17 #456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Support java 17 #456

wants to merge 2 commits into from

Conversation

egorklimov
Copy link

Hello!

I tried to run evosuite with Java 17. But it failed due to java modules error: module java.base does not "opens java.util" to unnamed module.

I added a library that supports opening models in runtime and updated xstream and asm versions. I also tried to add add-opens to jar manifest, but that didn't help. This solution is maybe not so good because it opens all modules,
maybe we should choose a set of modules and only open them.

It now at least works on java 17, but maybe we need to update the instrumentation too. I'm not familiar with the evosuite instrumentation, but if I can help support java 17 please let me know what I should do ;)

@egorklimov
Copy link
Author

I also tried this solution with java19 and it hangs without any log. I'll try to debug it

@egorklimov
Copy link
Author

I tried it on this simple app:

package org.example;

public class Main {

    public boolean is2(int target) {
        return target == 2;
    }

    public static void main(String[] args) {
        System.out.println(new Main().is2(2));
        System.out.println(new Main().checkObject(new Circle(1)));
    }
    
    record Human(String name, int age, String profession) {}
    record Circle(int radius) {}
    
    public String checkObject(Object obj) {
        if (obj instanceof Human h) {
            return "Name: %s, age: %s and profession: %s".formatted(h.name(), h.age(), h.profession());
        } else if (obj instanceof Circle c) {
            return "This is a circle %d".formatted(c.radius);
        }
        return "It is an object";
    }
}

And got the following tests:

/*
 * This file was automatically generated by EvoSuite
 * Thu Jun 01 10:40:06 GMT 2023
 */

package org.example;

import org.junit.Test;
import static org.junit.Assert.*;
import org.example.Main;
import org.junit.runner.RunWith;
import shaded.org.evosuite.runtime.EvoRunner;
import shaded.org.evosuite.runtime.EvoRunnerParameters;

@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, separateClassLoader = true) 
public class Main_ESTest extends Main_ESTest_scaffolding {

  @Test(timeout = 4000)
  public void test0()  throws Throwable  {
      Main main0 = new Main();
      Object object0 = new Object();
      String string0 = main0.checkObject(object0);
      assertEquals("It is an object", string0);
  }

  @Test(timeout = 4000)
  public void test1()  throws Throwable  {
      Main main0 = new Main();
      boolean boolean0 = main0.is2(3);
      assertFalse(boolean0);
  }

  @Test(timeout = 4000)
  public void test2()  throws Throwable  {
      Main.Human main_Human0 = new Main.Human("", 0, "");
      assertEquals("Human[name=, age=0, profession=]", main_Human0.toString());
  }

  @Test(timeout = 4000)
  public void test3()  throws Throwable  {
      Main main0 = new Main();
      Main.Human main_Human0 = new Main.Human("", 0, "");
      String string0 = main0.checkObject(main_Human0);
      assertEquals("Name: , age: 0 and profession: ", string0);
  }
}

@egorklimov
Copy link
Author

Could you restart tests? I tried them locally and it is green, maybe it is a flaky test

@v1d3rm3
Copy link

v1d3rm3 commented Aug 28, 2023

Solution with add-opens is not working in ubuntu openjdk 17

1 similar comment
@v1d3rm3
Copy link

v1d3rm3 commented Aug 28, 2023

Solution with add-opens is not working in ubuntu openjdk 17

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