-
Notifications
You must be signed in to change notification settings - Fork 601
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: added partial support for CONSTANT_Dynamic #2512
Conversation
Class files using condy (Dynamic class-file constant), like JaCoCo >= 0.8.4 creates them (see [1] and [2] for more details), causes errors we using Spotbugs to parse these class files. The `FooWithMember.clazz` embedded in this commit has been generated from this class source file: ```java package com.foo; class Foo { int a; public Foo(int a) { this.a = a; } public int getA() { return this.a; } } ``` These modifications don't completely fix the support of `CONSTANT_Dynamic`. We continue to have error from BCEL (maybe [3] is insufficient): ``` Exception analyzing com.foo.Foo using detector edu.umd.cs.findbugs.detect.FindNullDeref java.lang.IllegalArgumentException: Unknown or invalid constant type at 32 At org.apache.bcel.generic.LDC.getValue(LDC.java:113) At edu.umd.cs.findbugs.ba.vna.ValueNumberFrameModelingVisitor.visitLDC(ValueNumberFrameModelingVisitor.java:529) At org.apache.bcel.generic.LDC.accept(LDC.java:58) At edu.umd.cs.findbugs.ba.AbstractFrameModelingVisitor.analyzeInstruction(AbstractFrameModelingVisitor.java:84) At edu.umd.cs.findbugs.ba.vna.ValueNumberAnalysis.transferInstruction(ValueNumberAnalysis.java:228) At edu.umd.cs.findbugs.ba.vna.ValueNumberAnalysis.transferInstruction(ValueNumberAnalysis.java:57) At edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis.transfer(AbstractDataflowAnalysis.java:136) At edu.umd.cs.findbugs.ba.vna.ValueNumberAnalysis.transfer(ValueNumberAnalysis.java:214) At edu.umd.cs.findbugs.ba.vna.ValueNumberAnalysis.transfer(ValueNumberAnalysis.java:57) At edu.umd.cs.findbugs.ba.Dataflow.execute(Dataflow.java:378) At edu.umd.cs.findbugs.classfile.engine.bcel.ValueNumberDataflowFactory.analyze(ValueNumberDataflowFactory.java:76) At edu.umd.cs.findbugs.classfile.engine.bcel.ValueNumberDataflowFactory.analyze(ValueNumberDataflowFactory.java:46) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:368) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:321) At edu.umd.cs.findbugs.classfile.engine.bcel.AnalysisFactory.getValueNumberDataflow(AnalysisFactory.java:118) At edu.umd.cs.findbugs.classfile.engine.bcel.TypeDataflowFactory.analyze(TypeDataflowFactory.java:73) At edu.umd.cs.findbugs.classfile.engine.bcel.TypeDataflowFactory.analyze(TypeDataflowFactory.java:43) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:368) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:321) At edu.umd.cs.findbugs.classfile.engine.bcel.CFGFactory.analyze(CFGFactory.java:160) At edu.umd.cs.findbugs.classfile.engine.bcel.CFGFactory.analyze(CFGFactory.java:65) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:368) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:321) At edu.umd.cs.findbugs.classfile.engine.bcel.AnalysisFactory.getCFG(AnalysisFactory.java:93) At edu.umd.cs.findbugs.classfile.engine.bcel.DepthFirstSearchFactory.analyze(DepthFirstSearchFactory.java:49) At edu.umd.cs.findbugs.classfile.engine.bcel.DepthFirstSearchFactory.analyze(DepthFirstSearchFactory.java:32) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:368) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:321) At edu.umd.cs.findbugs.classfile.engine.bcel.AnalysisFactory.getDepthFirstSearch(AnalysisFactory.java:98) At edu.umd.cs.findbugs.classfile.engine.bcel.ValueNumberDataflowFactory.analyze(ValueNumberDataflowFactory.java:68) At edu.umd.cs.findbugs.classfile.engine.bcel.ValueNumberDataflowFactory.analyze(ValueNumberDataflowFactory.java:46) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.analyzeMethod(AnalysisCache.java:368) At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getMethodAnalysis(AnalysisCache.java:321) At edu.umd.cs.findbugs.ba.ClassContext.getMethodAnalysis(ClassContext.java:1010) At edu.umd.cs.findbugs.ba.ClassContext.getValueNumberDataflow(ClassContext.java:333) At edu.umd.cs.findbugs.detect.FindNullDeref.findPreviouslyDeadBlocks(FindNullDeref.java:301) At edu.umd.cs.findbugs.detect.FindNullDeref.analyzeMethod(FindNullDeref.java:271) At edu.umd.cs.findbugs.detect.FindNullDeref.visitClassContext(FindNullDeref.java:216) At edu.umd.cs.findbugs.DetectorToDetector2Adapter.visitClass(DetectorToDetector2Adapter.java:76) At edu.umd.cs.findbugs.FindBugs2.lambda$analyzeApplication$1(FindBugs2.java:1108) At java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) At edu.umd.cs.findbugs.CurrentThreadExecutorService.execute(CurrentThreadExecutorService.java:86) At java.base/java.util.concurrent.AbstractExecutorService.invokeAll(AbstractExecutorService.java:247) At edu.umd.cs.findbugs.FindBugs2.analyzeApplication(FindBugs2.java:1118) At edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:309) At edu.umd.cs.findbugs.FindBugs.runMain(FindBugs.java:395) ``` [1]: jacoco/jacoco@36b4e9c#diff-1d450b7247672d9362bac0ad7dfd7bd810e4293ab57f0100821a70a5e64e6911R56-R57 [2]: jacoco/jacoco#845 [3]: https://issues.apache.org/jira/browse/BCEL-362
There are some problems with the BCEL update currently. The errors in spotbugs will get fixed with #2278, but to merge it we need a new bcel release with apache/commons-bcel#221 merged. Can you please check if the changes from these two PRs solve the problem? (The bcel dependency needed to be modified to snapshot, because of the latter PR.) |
Same problem with bcel On the master branch, the method org/apache/bcel/generic/LDC::getValue() doesn't support |
Then there is a bcel issue as well. Can you please open an issue to them about this? |
Mmm My knowledge of Java / JaCoCo / ASM / bcel are very limited. I don't able to explain how If needed, I updated the issue #2503 with the Java source code and the class file generated by Java 17 + JaCoCo 0.8.9 which is causing problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue in BCEL hijacked the conversation a bit, but the PR itself does solve the problem about reading the file.
@@ -113,12 +114,16 @@ private void assertHasCodeBase(IScannableCodeBase codeBase) throws Exception { | |||
|
|||
@Test | |||
public void acceptConstantDynamic() throws Exception { | |||
String fileName = "../spotbugsTestCases/src/classSamples/recordCompileWithBazel6.2/Foo.clazz"; | |||
ArrayList<String> fileNames = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a comment about the class files (how to recreate them), and refer the issue here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please merge master to your branch?
Please, note that there were several changes, including migrating the tests from Junit Vintage to Jupiter, which may mean that some further adjustments are needed after the merge for a successful build.
Class files using condy (Dynamic class-file constant), like JaCoCo >= 0.8.4 creates them (see 36b4e9c7 and #845 for more details), causes errors we using Spotbugs to parse these class files.
The
FooWithMember.clazz
embedded in this commit has been generated from this class source file:These modifications don't completely fix the support of
CONSTANT_Dynamic
. We continue to have error from BCEL (maybe #BCEL-362 is insufficient):Issue: #2503