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

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String #333

Closed
moooonk opened this issue Apr 14, 2018 · 11 comments
Assignees
Milestone

Comments

@moooonk
Copy link

moooonk commented Apr 14, 2018

Hello @jbachorik
I use btrace-1.3.11 do some check in my project, and found this Exception.
I found my AOP funtion can not attach on some kind of Class with @location(value=Kind.SYNC_ENTRY).
I don't sure my problem has something to do with this Exception,but I think this Exception is bug.

btrace DEBUG: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
at com.sun.btrace.runtime.InstrumentingMethodVisitor.fromSlotType(InstrumentingMethodVisitor.java:1464)
at com.sun.btrace.runtime.InstrumentingMethodVisitor.visitVarInsn(InstrumentingMethodVisitor.java:683)
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitVarInsn(Unknown Source)
at com.sun.btrace.util.templates.TemplateExpanderVisitor.visitVarInsn(TemplateExpanderVisitor.java:79)
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitVarInsn(Unknown Source)
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitVarInsn(Unknown Source)
at com.sun.btrace.org.objectweb.asm.MethodVisitor.visitVarInsn(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.a(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.b(Unknown Source)
at com.sun.btrace.org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.runtime.BTraceClassReader.accept(BTraceClassReader.java:174)
at com.sun.btrace.org.objectweb.asm.ClassReader.accept(Unknown Source)
at com.sun.btrace.runtime.BTraceClassReader.accept(BTraceClassReader.java:183)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:177)
at com.sun.btrace.runtime.InstrumentUtils.accept(InstrumentUtils.java:171)
at com.sun.btrace.runtime.BTraceClassWriter.instrument(BTraceClassWriter.java:82)
at com.sun.btrace.runtime.BTraceTransformer.transform(BTraceTransformer.java:184)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:478)
at com.sun.btrace.agent.Main$3.run(Main.java:692)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

@jbachorik
Copy link
Collaborator

Could you share the method source causing this problem?
Thanks!

@moooonk
Copy link
Author

moooonk commented Apr 16, 2018

Source here.
And with my test,this source can run in btrace-1.3.8.3 no Exception.

package com.sun.btrace.samples;

import com.sun.btrace.annotations.;
import static com.sun.btrace.BTraceUtils.
;

@btrace(unsafe=true) public class AllMethods {
@OnMethod(
clazz="com.bt.pjg.game.backpack.BackpackService",
method="/.*/",
location=@location(value=Kind.SYNC_ENTRY)
)
public static void m() {
print("entered SYNC");
}

@OnMethod(
    clazz="com.bt.pjg.game.backpack.BackpackService",
    method="/.*/",
	location=@Location(value=Kind.ENTRY)
)
public static void m2() {
    print("entered run");
}

}

@jbachorik
Copy link
Collaborator

I guess BackpackService is a closed source. I will try to figure out the problem from the available data. This is all due to stackframe maps in bytcode - it is very complex area without extensive documentation unfortunately :( Thanks for patience!

@moooonk
Copy link
Author

moooonk commented Apr 16, 2018

BackpackService is My company project source.I'm sorry.It's not convenient for me to share the detail source.
But I can share the source structure.I hope it will help you。

public class BackpackService {
private static final BackpackService instance = new BackpackService();

private BackpackManger manager;

private BackpackService() {
	
}

public static BackpackService instance() {
	return instance;
}

public void init() {
	
}

public CacheMap<ItemBase> getItemMap(long userId) {
	
}

public List<ItemBase> getItemList(long userId) {
	
}

public ItemBase getItemById(long userId, int itemId) {
	
}

public int getItemCount(long userId, int itemId) {
	
}

public ItemBase addItem(User user, int itemId, int count, GetApproach getApproach) {

}

public List<ItemBase> addItem(User user, Collection<M2QEntry> entryList, GetApproach getApproach) {

}

private void throwInvalidParamsException(M2QEntry entry) {
	
}

public boolean decrItem(User user, int itemId, int count, DecReason decReason) {
	
}

public boolean decrItem(User user, Collection<M2QEntry> entryList, DecReason decReason) {
	
	
}

public void replaceItem(User user, ItemBase itemBase) {
	
}

private void replaceItem(User user, Collection<ItemBase> itemBaseList) {
	
}

private void pushChange(User user, Collection<ItemBase> itemBaseList) {
	
}

public List<UserItem> changeToUserItem(Collection<ItemBase> itemBaseList) {
	synchronized (this) {
		synchronized (itemBaseList) {
			
			}			
			return userItemList;				
		}
	}
}

public short useTool(User user, List<M2QEntry> m2qList, long targetId) {
	
}

public boolean checkEnough(User user, int itemId, int count) {
	
}

public boolean checkEnough(User user, Collection<M2QEntry> entryList) {
	
}

}

@jbachorik jbachorik self-assigned this Apr 30, 2018
@jbachorik jbachorik added this to the 1.3.12 milestone Apr 30, 2018
@jbachorik
Copy link
Collaborator

Can you, please, try with #341 fix applied? I discovered another corner case in stackframe map generation and fixed that - might fix also your issue, with some luck.

@jbachorik
Copy link
Collaborator

Ping. Any chance to test this fix to see whether the problem goes away?

@moooonk
Copy link
Author

moooonk commented Jun 4, 2018

Unfortunately,I donwload new btrace-bin-1.3.11 release and test.But this bug still here.

@jbachorik
Copy link
Collaborator

jbachorik commented Aug 26, 2018

Could you try a custom built BTrace containing commit #527d86f265a0b534791309b42303879aa44da7ae ?
I added more debug info there to figure out what is throwing the stack tracing logic off.

@moooonk
Copy link
Author

moooonk commented Sep 15, 2018

log here:


btrace WARNING: Unknown slot type: -2



btrace WARNING: Unknown slot type: -2




@jbachorik
Copy link
Collaborator

Any chance of sharing the compiled version of that class? I can sign whatever non-disclosure agreement if necessary and you can send it directly to my email.
Without that, I am afraid, I won't be able to solve this problem - there seems to be some peculiarity in the stackframe maps in that class and it is throwing off the algorithm used to recompute them in instrumented methods.

@jbachorik
Copy link
Collaborator

Hi, I addressed this issue in develop branch. Can you, please, verify?

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

No branches or pull requests

2 participants