Hi Marc,

Please find the full stack.
ava.io.IOException: Error while instrumenting
oracle/apps/scm/productModel/items/ui/bean/ItemOverviewBean.
at org.jacoco.core.instr.Instrumenter.instrumentError(Instrumenter.java:159)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:109)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:134)
at
ree.PerTestCoverageCollector$2.visitClassExecution(PerTestCoverageCollector.java:572)
at
org.jacoco.core.data.ExecutionDataReader.readExecutionData(ExecutionDataReader.java:151)
at
org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:116)
at
org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:93)
at ree.PerTestCoverageCollector.dump(PerTestCoverageCollector.java:692)
at
ree.PerTestCoverageCollector.executeTest(PerTestCoverageCollector.java:211)
at ree.PerTestCoverageManager.main(PerTestCoverageManager.java:97)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 6
at
org.jacoco.core.internal.instr.InstrSupport.getMajorVersion(InstrSupport.java:176)
at
org.jacoco.core.internal.instr.InstrSupport.classReaderFor(InstrSupport.java:275)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:75)
at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:107)
... 8 more

The Code I was trying out is as below
public void dump(InputStream in) throws Exception {
File output_file = new File((configData.get("OUTPUT_FILE_DIR") +
TESTCASE_NAME + "#"+configData.get("TEST_NUM")+(".txt")));
System.out.println("TestCase: "+TESTCASE_NAME);
System.out.println("OUTPUT_FILE_DIR: "+configData.get("OUTPUT_FILE_DIR"));
System.out.println(configData.get("OUTPUT_FILE_DIR") + TESTCASE_NAME +
".txt");
output_file.createNewFile();
final PrintStream out = new PrintStream(new FileOutputStream(output_file,
false));

out.println("CLASS ID         HITS/PROBES   CLASS NAME");
System.out.println("INDATE in"+in);
//String results = new BufferedReader (new
InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
//System.out.println("INDATE"+results);
final ExecutionDataReader reader = new ExecutionDataReader(in);
reader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(final SessionInfo info) {
out.printf("Session \"%s\": %s - %s%n", info.getId(), new
Date(info.getStartTimeStamp()),
new Date(info.getDumpTimeStamp()));
}
});

reader.setExecutionDataVisitor(new IExecutionDataVisitor() {
public void visitClassExecution(final ExecutionData data) {
CLASS_NAME =
data.getName();//"oracle/apps/scm/productModel/items/ui/bean/ItemOverviewBean";//
long CLASS_ID = data.getId();
Date todayDate = new Date();
final DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println("Today DAte is :" + sdf.format(todayDate));
System.out.println("CLASS_NAME:"+CLASS_NAME);
System.out.println("CLASS_ID:"+CLASS_ID);
//Test method level coverage
/*************************************************************************************/

// For instrumentation and runtime we need a IRuntime instance
       // to collect execution data:
try{
       final IRuntime runtime = new LoggerRuntime();

       // The Instrumenter creates a modified version of our test target
class
       // that contains additional probes for execution data recording:
       final Instrumenter instr = new Instrumenter(runtime);
       InputStream original = getTargetClass();
       final byte[] instrumented = instr.instrument(original, CLASS_NAME);
       original.close();

       // Now we're ready to run our instrumented class and need to startup
the
       // runtime first:
       final RuntimeData dataRunTime = new RuntimeData();
       runtime.startup(dataRunTime);

       // In this tutorial we use a special class loader to directly load
the
       // instrumented class definition from a byte[] instances.
       final MemoryClassLoader memoryClassLoader = new MemoryClassLoader();
       memoryClassLoader.addDefinition(CLASS_NAME, instrumented);
       final Class<?> targetClass = memoryClassLoader.loadClass(CLASS_NAME);

       // Here we execute our test target class through its Runnable
interface:
       final Runnable targetInstance = (Runnable) targetClass.newInstance();
       targetInstance.run();

       // At the end of test execution we collect execution data and
shutdown
       // the runtime:
       final ExecutionDataStore executionData = new ExecutionDataStore();
       final SessionInfoStore sessionInfos = new SessionInfoStore();
       dataRunTime.collect(executionData, sessionInfos, false);
       runtime.shutdown();

       // Together with the original class definition we can calculate
coverage
       // information:
       final CoverageBuilder coverageBuilder = new CoverageBuilder();
       final Analyzer analyzer = new Analyzer(executionData,
coverageBuilder);
       original = getTargetClass();
       analyzer.analyzeClass(original, CLASS_NAME);
       original.close();

       // Let's dump some metrics and line coverage information:
       for (final IClassCoverage cc : coverageBuilder.getClasses()) {
           out.printf("Coverage of class %s%n", cc.getName());

           printCounter("instructions", cc.getInstructionCounter());
           printCounter("branches", cc.getBranchCounter());
           printCounter("lines", cc.getLineCounter());
           printCounter("methods", cc.getMethodCounter());
           printCounter("complexity", cc.getComplexityCounter());

           for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {
               out.printf("Line %s: %s%n", Integer.valueOf(i),
                       getColor(cc.getLine(i).getStatus()));
           }
       }
}catch(Exception e){
e.printStackTrace();

}
/***************************************************************************************/

}
//}
});
reader.read();
in.close();
System.out.println();
}
/** Currently hardcoded the file details to validate **/
public InputStream getTargetClass() throws Exception{
InputStream fs = new FileInputStream(CLASSPATH);
System.out.println(fs.toString());
String results = new BufferedReader (new
InputStreamReader(fs)).lines().collect(Collectors.joining("\n"));
System.out.println("INDATE"+results);
return fs;
}

Thanks,
Prabitha


On Wed, Aug 24, 2022 at 6:48 PM Marc Hoffmann <[email protected]>
wrote:

> Hi Prabitha,
>
> please provide the full stack trace, this will probably show the root
> cause.
>
> Regards,
> -marc
>
> On 24. Aug 2022, at 14:31, Prabitha Susil <[email protected]> wrote:
>
> Hi,
>
> I am using org.jacoco.core-0.8.6.202001130357.jar, asm-8.0.1.jar with Java
> 8. While trying to read a .class files, i am getting error -
> java.io.IOException: Error while instrumenting.
>
> Any pointers would be of great help.
>
> Thanks,
> Prabitha
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "JaCoCo and EclEmma Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jacoco/3ea8a508-ba9d-4bd3-b03b-54af55c2ae19n%40googlegroups.com
> <https://groups.google.com/d/msgid/jacoco/3ea8a508-ba9d-4bd3-b03b-54af55c2ae19n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "JaCoCo and EclEmma Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jacoco/06B15C88-5497-4EEF-9605-A4E01BEC5E8F%40mountainminds.com
> <https://groups.google.com/d/msgid/jacoco/06B15C88-5497-4EEF-9605-A4E01BEC5E8F%40mountainminds.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/CAMf5NwQjC4uzKz8TXWBvr5TW3NtTtVZhf5D%3DpDt%2BmQeqPUvWgg%40mail.gmail.com.

Reply via email to