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

Use ByteBuddy to instrument classes instead Javassist #727

Open
thekingn0thing opened this issue Dec 1, 2016 · 58 comments
Open

Use ByteBuddy to instrument classes instead Javassist #727

thekingn0thing opened this issue Dec 1, 2016 · 58 comments
Assignees
Milestone

Comments

@thekingn0thing
Copy link
Member

@thekingn0thing thekingn0thing commented Dec 1, 2016

The main issue with Javassist it's that it read classes from disk before instrumenting. Such behaviour breaks compatibility with other tools which are instrumenting classes (see discussion jacoco/jacoco#51)

ByteBuddy could help us to resolve the issue and supporting online Jacoco Instrumenting.

ByteBudy agent has to be used for implementation of powermock-agent

@thekingn0thing thekingn0thing added this to the PowerMock 2.0.0 milestone Dec 1, 2016
@thekingn0thing thekingn0thing mentioned this issue Dec 1, 2016
6 of 6 tasks complete
thekingn0thing pushed a commit that referenced this issue Mar 18, 2017
Arthur Zagretdinov
Refactoring MockClassLoader  - extract Javassist relative code to a new classes.

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
thekingn0thing pushed a commit that referenced this issue Mar 18, 2017
Refactoring MockClassLoader  - extract Javassist relative code to a new classes.

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
@thekingn0thing thekingn0thing self-assigned this Mar 18, 2017
thekingn0thing pushed a commit that referenced this issue Apr 17, 2017
Refactoring MockClassLoader  - extract Javassist relative code to a new classes.
thekingn0thing pushed a commit that referenced this issue Apr 17, 2017
Refactoring MockTransformer  - split transformer to set of small classes.
thekingn0thing pushed a commit that referenced this issue Apr 17, 2017
Refactoring MockClassLoader  - extract Javassist relative code to a new classes.
thekingn0thing pushed a commit that referenced this issue Apr 17, 2017
Refactoring MockTransformer  - split transformer to set of small classes.
@fabriziomieli
Copy link

@fabriziomieli fabriziomieli commented Apr 26, 2017

Hi, When this is supposed to be ready?

@thekingn0thing
Copy link
Member Author

@thekingn0thing thekingn0thing commented Apr 26, 2017

@fabriziomieli
Copy link

@fabriziomieli fabriziomieli commented Apr 27, 2017

Thank you very much

thekingn0thing pushed a commit that referenced this issue May 1, 2017
Arthur Zagretdinov
Implement modifiers related transformer

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
thekingn0thing pushed a commit that referenced this issue May 1, 2017
Arthur Zagretdinov
Implement static initialiser transformer

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
thekingn0thing pushed a commit that referenced this issue Jun 18, 2017
Refactoring MockClassLoader  - extract Javassist relative code to a new classes.
thekingn0thing pushed a commit that referenced this issue Jun 18, 2017
Refactoring MockTransformer  - split transformer to set of small classes.
thekingn0thing pushed a commit that referenced this issue Jun 18, 2017
Implement modifiers related transformer

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
thekingn0thing pushed a commit that referenced this issue Jun 18, 2017
Implement static initialiser transformer

Signed-off-by: Arthur Zagretdinov <arthur.zagretdinov@outlook.com>
thekingn0thing pushed a commit that referenced this issue Jun 18, 2017
Arthur Zagretdinov
Fix issues after merging with master
@peter-janssen
Copy link

@peter-janssen peter-janssen commented Jul 7, 2017

Will you release this feature when it is ready or only as part of PowerMock 2.0?

@thekingn0thing
Copy link
Member Author

@thekingn0thing thekingn0thing commented Jul 7, 2017

I'm going to release it as part of PowerMock 2.0, because the change for ButyBuddy is close intertwined with clearing PowerMock from copy-pasted mockito code.

@peter-janssen
Copy link

@peter-janssen peter-janssen commented Jul 8, 2017

The 2.0 release looks quite big so I guess the earlier estimate of end of june (you did mean 2017, right?) will be pushed back quite a bit?

@benken-parasoft
Copy link

@benken-parasoft benken-parasoft commented Sep 12, 2018

Thanks for the update. For background, enterprise users like myself are moving ahead with newer java releases which now release every six months. For existing unit test bases that use powermock, we have to either switch to 2.x or hold our entire unit test bases to older java versions.

the last beta was released last May

Thanks for the clarification. I only found the source tag but not any released binaries. Up until now, I've always pulled powermock releases from maven central, including the latest 1.7.4 release from April. Are you no longer releasing binaries to maven central for 2.x? Was this intentional or an oversight? Or should users stop using maven central and use the maven repository from bintray instead?

@thekingn0thing
Copy link
Member Author

@thekingn0thing thekingn0thing commented Oct 7, 2018

@benken-parasoft,

I only found the source tag but not any released binaries. Up until now, I've always pulled powermock releases from maven central, including the latest 1.7.4 release from April. Are you no longer releasing binaries to maven central for 2.x? Was this intentional or an oversight?

It was done intentionally as I don't want to span Maven Central with a lot of beta version. PowerMocks migrated to continue delivery, so it means that each pull request merged to release branches is being published to a repository as an artifact. However, I understood that could development PowerMock 2.0 could take a lot time (not so many as it already has taken), I decided to split beta release to Bintray and GA release to maven central.

@thekingn0thing
Copy link
Member Author

@thekingn0thing thekingn0thing commented Oct 24, 2018

I'm excluding this feature from PowerMock 2.0.0 as working on it took to many time and I'm not able to finish it in near future. I will release PowerMock 2.0.0 with all changes and full supporting Mockito 2.x and then will continue work on this feature as a part of PowerMock 3.x where I will drop supporting Java less than 1.8

@Tibor17
Copy link

@Tibor17 Tibor17 commented Oct 24, 2018

@thekingnothing
I respect your decision.
I think here your work is to use very low level bytecode instructions. I saw similar work in JaCoCo project. So. If you involved committers from JaCoCo, their experiences would be beneficial and you would have more spare time for yourself.

thekingn0thing pushed a commit that referenced this issue Oct 24, 2018
Arthur Zagretdinov
)

Preparing PowerMock 2.0 Release without ByteBuddy 

* Remove all ByteBuddy Classloader code (#727)
* Fix tests
* Update Libraries
@thekingn0thing thekingn0thing removed this from In progress in PowerMock 2.x Oct 24, 2018
@benken-parasoft
Copy link

@benken-parasoft benken-parasoft commented Nov 5, 2018

@thekingnothing, I notice ByteBuddy changes backed out as part of PR 948. Then I saw PR 910 mentioned in the release notes 2.0.0 RC1 but I assume this is just referring to what you had backed out. However, I still might not be understanding these changes correctly. Can you clarify what is or isn't being included with respect to ByteBuddy for the 2.0.0 release?

I am primarily concerned about java version support. My organization needs to be able to support new Java releases as they come out, which is now every six months. Based on my observations, this appears to depend on which version of what byte code library being used, ByteBuddy vs Javassist. For example, I seemed to be able to do static mocking in Java 11 with PowerMock 2.0.0 beta 11 with Mockito 2.23 and ByteBuddy 1.9. So, if PowerMock 2.0.0 switches back to using Javassist then will static mocking no long work in java > 8 again? To support new java, such as java 11, will I be able to switch to the 2.0.0 release or should I should stay on beta 11 or use later a 3.0 snapshot with preliminary ByteBuddy support re-introduced?

@benken-parasoft
Copy link

@benken-parasoft benken-parasoft commented Nov 6, 2018

I am primarily concerned about java version support.

With PowerMock 22 using Javassist again, it looks like PowerMock would only work with Java 9 but not 10 or 11. At least, the pom.xml for PowerMock 2.0.0-RC.2 shows a dependency on Javassist 3.22.0-GA which looks to support Java 9. Perhaps it be possible to use PowerMock with Javassist 3.24.0-GA for Java 11 support instead? Previously, with PowerMock 2.0.0 beta 11, I was able to use ByteBuddy 1.9 for Java 11 support.

@thekingn0thing
Copy link
Member Author

@thekingn0thing thekingn0thing commented Nov 17, 2018

@benken-parasoft

I agree that ByteBuddy is a great well-supported library. However, it does not cover all PowerMock needs, at least for now.

It’s well applied when you need advice your code or generates a code. However, to support such features as constructor stubbing, mocking constructor calls or mocking System class I have to modify bytecode in instruction level where ByteBuddy features end. I have only one option - use ASM in addition to ByteBuddy. As it means that I have to:

  • go deep into JVM implantation.
  • manually track stack, local variables and so on (with a help from the ByteBuddy side, however, there are still a lot of work to do)
  • care about JVM changes and aspect of implementation

As result, it takes a lot of time to implement the features that already worked with Javassist. I tried to implement it for 6 months, however, with a time that I can give to PowerMock I did not achieve a big progress. The task is too complicated. You need fully focus on it - what hardly achievable when you work for 30-60 minutes per day.

I’m not going to stop working at all on migrating to ByteBuddy. I just changed priorities to be able to release what was already implemented the year ago.

At the end of the day, my decision is aimed to be able to deliver supporting new Java. Thank @ijuma, he provided the pull request to support Java 11 (#952) and @eolivelli who raised the pull request with the fix for Java 12 (#939).

@jhyry-gcpud
Copy link

@jhyry-gcpud jhyry-gcpud commented Jan 31, 2019

Is this issue still on the table?

@Tibor17
Copy link

@Tibor17 Tibor17 commented Jan 31, 2019

I understand it so that ByteBuddy should be on the table. Without it the JaCoCo report would not cover these tests with PowerMock or Mockito. At least this is my understanding, and some people would see other reasons especially internal ones in PowerMock.

@nEdAy
Copy link

@nEdAy nEdAy commented Mar 6, 2019

Is this issue still on the table?

@vijjukumar
Copy link

@vijjukumar vijjukumar commented Mar 21, 2019

Is this issue still on the table ? we do have any alternative approach. Thanks

@Vampire
Copy link
Contributor

@Vampire Vampire commented Sep 15, 2019

How is the current state of this?
I used JaCoCo online instrumentation with PowerMock for mocking a system class.
It seems there was JaCoCo data recorded, but it doesn't match the class files when the report is generated, so I guess only the order of instrumentation is a problem maybe?

@ninjubohra
Copy link

@ninjubohra ninjubohra commented Oct 11, 2019

Hello,

Just another user affected by the 'zero' JaCoCo results with Powermock 😢
The top of this issue thread now says that the issue was fixed by another issue (#911 )

If so can somebody do the following:

  • Add an 'affirmative' message to the thread and close issue
  • Update the Powermock documentation here to reflect the updated state
  • Have a virtual cookie in appreciation of all the hard work that goes into supporting a great tool like Powermock (thanks!) 🍪
@Techtony96
Copy link

@Techtony96 Techtony96 commented Dec 13, 2019

The PR #911 that says fixes this issue is unrelated and must be a typo in the commit message.

As a user eagerly awaiting online instrumentation I thank you for all the hard work towards this goal.

@fredwilliamson
Copy link

@fredwilliamson fredwilliamson commented Jan 9, 2020

Hello ByteBuddy implementation will be in your next release ?
BR

@chengyinjie
Copy link

@chengyinjie chengyinjie commented Mar 10, 2020

Really looking forward to the ByteBuddy release to fix the Jacoco problem.

@minhnguyenvan95
Copy link

@minhnguyenvan95 minhnguyenvan95 commented Apr 22, 2020

Looking forward to ByteBuddy release

@OluwoleOyetoke
Copy link

@OluwoleOyetoke OluwoleOyetoke commented Apr 30, 2020

Really looking forward to the ByteBuddy release

1 similar comment
@splf32
Copy link

@splf32 splf32 commented May 27, 2020

Really looking forward to the ByteBuddy release

@SangHakLee
Copy link

@SangHakLee SangHakLee commented Jun 1, 2020

Really looking forward to the ByteBuddy release.

I want to use JaCoCo and Powermock comfortably.

@jhyry-gcpud
Copy link

@jhyry-gcpud jhyry-gcpud commented Jun 21, 2020

Been watching this thread for over a year.
Any progress?

@sarajcarbajal
Copy link

@sarajcarbajal sarajcarbajal commented Nov 25, 2020

any progress with this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.