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

ClassCastException: LineTouchPointDescriptor cannot be cast to JumpTouchPointDescriptor #40

Closed
nhnb opened this issue Jul 11, 2013 · 9 comments
Assignees
Labels

Comments

@nhnb
Copy link

nhnb commented Jul 11, 2013

I get the following ClassCastException with latest Cobertura git master on 4 files during instrumentation. All of them are static inner classes within interfaces, but this might be a coincidence.

[cobertura-instrument] java.lang.ClassCastException: net.sourceforge.cobertura.instrument.tp.LineTouchPointDescriptor cannot be cast to net.sourceforge.cobertura.instrument.tp.JumpTouchPointDescriptor


net.sourceforge.cobertura.instrument.tp.ClassMap.getCounterIdForJumpTrue
                  (ClassMap.java:204)
net.sourceforge.cobertura.instrument.pass3.InjectCodeTouchPointListener.beforeJump
                  (InjectCodeTouchPointListener.java:68)
net.sourceforge.cobertura.instrument.FindTouchPointsMethodAdapter.visitJumpInsn                   (FindTouchPointsMethodAdapter.java:246)
org.objectweb.asm.MethodVisitor.visitJumpInsn
org.objectweb.asm.tree.JumpInsnNode.accept
org.objectweb.asm.tree.InsnList.accept
org.objectweb.asm.tree.MethodNode.accept
org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd
org.objectweb.asm.MethodVisitor.visitEnd
org.objectweb.asm.util.CheckMethodAdapter.visitEnd
org.objectweb.asm.ClassReader.b(Unknown Source)
org.objectweb.asm.ClassReader.accept(Unknown Source)
org.objectweb.asm.ClassReader.accept(Unknown Source)
net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass
                  (CoberturaInstrumenter.java:204)
net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass
                  (CoberturaInstrumenter.java:121)
net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass
                  (CoberturaInstrumenter.java:233)
net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass
                  (Main.java:274)
net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:283)
net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:373)
net.sourceforge.cobertura.instrument.Main.main(Main.java:395)
@nhnb
Copy link
Author

nhnb commented Jul 11, 2013

.java and .class files to reproduce the issue with: http://filebin.ca/ndveXhpYQSw

@ghost ghost assigned christ66 Jul 11, 2013
@christ66
Copy link
Member

I had no issues with instrumenting the 2 binary files provided. I tried creating a simple test case with multiple static inner classes, but can't reproduce.

We could always change the getCounterIdForJumpTrue and getCounterIdForJumpFalse methods to have an instanceof check to prevent a ClassCastException.

    public Integer getCounterIdForJumpTrue(int eventId) {
        if (eventId2touchPointDescriptor.get(eventId) instanceof JumpTouchPointDescriptor) {
            JumpTouchPointDescriptor jumpTouchPointDescriptor = (JumpTouchPointDescriptor) eventId2touchPointDescriptor
                    .get(eventId);
            if (jumpTouchPointDescriptor != null) {
                return jumpTouchPointDescriptor.getCounterIdForTrue();
            }
        }

        return null;
    }

@gronono
Copy link

gronono commented Jul 16, 2013

I got the same error with the 2.0.2 version and java 7.
The underlying class have not inner classes. It has some annotations (service and override)

@ghost
Copy link

ghost commented Jul 16, 2013

I also got the same error with java 7 and 2.0.1 version. What is estimated time for releasing 2.0.3 version.?

christ66 added a commit that referenced this issue Jul 16, 2013
christ66 added a commit that referenced this issue Jul 16, 2013
Fix issue #40 and #42 and remove custom javancss code.
@christ66
Copy link
Member

I just merged in a fix for this issue, can you check out the latest code:
git clone https://github.com/cobertura/cobertura
and run the command:
mvn package -DskipTests
and in the target folder there will be a snapshot version of the latest jar, could you test that jar and verify that this issue doesn't exist anymore?

@ghost
Copy link

ghost commented Jul 16, 2013

sure, will let you know, thank you :)

@ghost
Copy link

ghost commented Jul 16, 2013

I am not seeing this issue anymore. thank you

@D-Bugs
Copy link

D-Bugs commented Jul 23, 2013

There are the same issue for :

  • getCounterIdForLineEventId
  • getCounterIdForSwitch

@christ66 christ66 reopened this Jul 23, 2013
@christ66
Copy link
Member

I will make the same code changes to fix this also. Thanks for the heads up.

christ66 added a commit that referenced this issue Jul 24, 2013
christ66 added a commit that referenced this issue Jul 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants