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

fix gzoltar.cli ClassCastException in Java11 #41

Merged
merged 2 commits into from
Apr 16, 2021

Conversation

gynther-k
Copy link
Contributor

Context

When running gzoltar.cli with the latest version 51967a3 with:

java … com.gzoltar.agent.rt-1.7.3-SNAPSHOT-all.jar … com.gzoltar.cli-1.7.3-SNAPSHOT-jar-with-dependencies.jar
com.gzoltar.cli.Main runTestMethods …… --collectCoverage

with Java11 projects, i get the error:


   ____ _____ 	_ _          	 
  / ___|__  /___ | | |_ __ _ _ __   
 | |  _  / // _ \| | __/ _` | '__|
 | |_| |/ /| (_) | | || (_| | |	 
  \____/____\___/|_|\__\__,_|_|

* Run test methods in isolation.
Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
    at com.gzoltar.cli.commands.RunTestMethods.execute(RunTestMethods.java:81)
    at com.gzoltar.cli.Main.execute(Main.java:105)
    at com.gzoltar.cli.Main.main(Main.java:40)

Therefore I did this small modification to use it with my project. Do you think this is helpful to get gzoltar.cli to work with Java 11?

Check lists

  • Unit tests
  • [ X ] Test pass
  • [ X ] Coding style (indentation, etc)

@monperrus
Copy link

@jose FYI, @gynther-k is my student at KTH working on program repair. This PR enables us to run our repair tools on recent bugs. Thanks!

com.gzoltar.cli/pom.xml Outdated Show resolved Hide resolved
@jose
Copy link
Member

jose commented Apr 15, 2021

Hi @gynther-k,

First of all thanks for taking the time to improve GZoltar.

I've just ran a quick example and your pull request do indeed address the issue reported, which I believe occurs when GZoltar is used under Java >= 9. I left a couple comments in your code and it would be great if could please address/comment them.

--
Best,
Jose

@jose jose mentioned this pull request Apr 15, 2021
@lapplislazuli
Copy link

I can confirm it works on Java 15 too 😄 Thank you @gynther-k

@gynther-k
Copy link
Contributor Author

gynther-k commented Apr 16, 2021

Thank you for the comments on the code. The code was done in a hurry for my project. This looks nicer and I have tried it, I will update the PR 😄

@lapplislazuli
Copy link

just on a last note, despite it might not be an issue with this PR:
I was running on the cli.examples and
when doing ./run.sh --instrumentation online everything works as inspected, but on ./run.sh --instrumentation offline it fails with the following output:

$ ./run.sh --instrumentation offline
Compile source and test cases ...
Collect list of unit test cases to run ...
   ____ _____     _ _               
  / ___|__  /___ | | |_ __ _ _ __   
 | |  _  / // _ \| | __/ _` | '__| 
 | |_| |/ /| (_) | | || (_| | |     
  \____/____\___/|_|\__\__,_|_| 

* List all (JUnit/TestNG) unit test cases in a provided classpath.
Perform offline instrumentation ...
   ____ _____     _ _               
  / ___|__  /___ | | |_ __ _ _ __   
 | |  _  / // _ \| | __/ _` | '__| 
 | |_| |/ /| (_) | | || (_| | |     
  \____/____\___/|_|\__\__,_|_| 

* Off-line instrumentation of Java class files and jar files.
* Processing
  - /Users/user/gzoltar/com.gzoltar.cli.examples/.build
* 0 classes instrumented to /Users/user/gzoltar/com.gzoltar.cli.examples/build
* Done!
Run each unit test case in isolation ...
   ____ _____     _ _               
  / ___|__  /___ | | |_ __ _ _ __   
 | |  _  / // _ \| | __/ _` | '__| 
 | |_| |/ /| (_) | | || (_| | |     
  \____/____\___/|_|\__\__,_|_| 

* Run test methods in isolation.
java.lang.AssertionError: expected:<2> but was:<3>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	...

org.gzoltar.examples.CharacterCounterTest#test1 has finished! Has it failed? true
org.gzoltar.examples.CharacterCounterTest#test2 has finished! Has it failed? false
java.lang.AssertionError: expected:<1> but was:<2>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	[...]

org.gzoltar.examples.CharacterCounterTest#test3 has finished! Has it failed? true
java.lang.AssertionError: expected:<2> but was:<4>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	[...]

org.gzoltar.examples.CharacterCounterTest#test4 has finished! Has it failed? true
org.gzoltar.examples.CharacterCounterTest#test5 has finished! Has it failed? false
java.lang.AssertionError: expected:<7> but was:<9>
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	[...]

org.gzoltar.examples.CharacterCounterTest#test7 has finished! Has it failed? true
org.gzoltar.examples.CharacterCounterTest#test8 has finished! Has it failed? false
* Done!
/Users/user/gzoltar/com.gzoltar.cli.examples/build/gzoltar.ser does not exist or it is empty!

It seems however that just something with the paths is wrong so it doesn't find the instrumented files.
Also, Test6 seems to be missing, somehow.

@gynther-k
Copy link
Contributor Author

@lapplislazuli
I get the same result as you when i run offline instrumentation without my fix, and the default gzoltar version 1.7.3 with Java 8.
The Test 6 is commented out I think:

https://github.com/GZoltar/gzoltar/blob/master/com.gzoltar.cli.examples/test/org/gzoltar/examples/CharacterCounterTest.java
  /*@Test
  public void test6() {
    CharacterCounter cc = new CharacterCounter();
    cc.processString("\0x10\0x05\0x00");
    assertEquals(0, cc.getNumLetters());
    assertEquals(0, cc.getNumDigits());
    assertEquals(3, cc.getNumOtherCharacters());
  }*/

@jose jose merged commit a5b12e9 into GZoltar:master Apr 16, 2021
@jose
Copy link
Member

jose commented Apr 16, 2021

Thanks @lapplislazuli for checking whether the offline mode was working and thanks @gynther-k for the pull request.

  • test6 is commented out and therefore is not executed by GZoltar.
  • The underline reason why there is not a gzoltar.ser file after executing all test cases (in offline mode) is because GZoltar did not even manage to instrument any class. (It has been fixed in commit a57904e.)
  • 0 classes instrumented to /Users/user/gzoltar/com.gzoltar.cli.examples/build

I ran a few combinations of GZoltar and Java 8/12 and here are my findings.

Online

Java 8 Java 12
1.7.3-SNAPSHOT (51967a3) OK FAIL -- ClassCastException
1.7.3-SNAPSHOT (#41) OK OK
1.7.3-SNAPSHOT (a57904e) OK OK

Offline

Java 8 Java 12
1.7.3-SNAPSHOT (51967a3) OK FAIL -- ClassCastException
1.7.3-SNAPSHOT (#41) OK FAIL -- 0 classes instrumented
1.7.3-SNAPSHOT (a57904e) OK OK

Please do let me know if version a57904e does not work on your end.

--
Best,
Jose

@monperrus
Copy link

Thanks a lot @gynther-k and @jose!

@monperrus
Copy link

@jose would you be able to release this change on Maven Central? That would be super useful. Thanks!

@jose
Copy link
Member

jose commented Nov 17, 2021

@monperrus, will do. ETA, end of the month.

@monperrus
Copy link

monperrus commented Nov 17, 2021 via email

@jose
Copy link
Member

jose commented Mar 23, 2022

@monperrus, just to let you know that I've finally managed to find the time to release a new version of GZoltar (i.e., v1.7.3) on Maven Central Repository.

@monperrus
Copy link

thanks a lot @jose

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.

4 participants