Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 350741

Summary: NotFoundException in ClassPool.get method while using javassist
Product: [Eclipse Project] JDT Reporter: sagar <sagarv_shinde>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED INVALID QA Contact:
Severity: enhancement    
Priority: P3 CC: Olivier_Thomann
Version: 3.6.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description sagar CLA 2011-06-29 14:57:50 EDT
Build Identifier: eclipse3.6.1

Hello
I am trying to use javassist in eclipse. I have added javassist.jar file to project. I can import the classes in javassist package. but for a simple program getting an error in the ClassPool.get method. NotFoundException. 
Here are the program details.

package temp;

public class Hello {

public void say() {
System.out.println("Hello");
}
}
__________________________________________
// 2nd program tries to modify the bytecode of Hello. 
package temp;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;

public class Test {
public static void main(String[] args) throws Exception {

ClassPool cp = ClassPool.getDefault();

CtClass cc = cp.get("Hello"); // getting NotFoundException here..

CtMethod m = cc.getDeclaredMethod("say");
m.insertBefore("{ System.out.println(\"Hello.say():\"); }");
Class c = cc.toClass();
Hello h = (Hello)c.newInstance();
h.say();

System.out.println("test prog:");
}

}


Reproducible: Always

Steps to Reproduce:
1.create temp package.
2.Copy Hello.java program in eclipse.
3.Copy Test.java program in eclipse.
3.Add javassist.jar file through buildpath option.
4. execute Test.java
Comment 1 Olivier Thomann CLA 2011-06-29 15:16:26 EDT
This should belong to JDT/Core
Comment 2 Olivier Thomann CLA 2011-06-29 15:23:58 EDT
You need to put "temp.Hello" for the class name as your class belongs to a named package "temp".
Once you have:
package temp;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;

public class Test {
	public static void main(String[] args) throws Exception {

		ClassPool cp = ClassPool.getDefault();

		CtClass cc = cp.get("temp.Hello"); // getting NotFoundException here..

		CtMethod m = cc.getDeclaredMethod("say");
		m.insertBefore("{ System.out.println(\"Hello.say():\"); }");
		Class c = cc.toClass();
		Hello h = (Hello) c.newInstance();
		h.say();

		System.out.println("test prog:");
	}

}

your code runs fine.
Closing as INVALID.