Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350741 - NotFoundException in ClassPool.get method while using javassist
Summary: NotFoundException in ClassPool.get method while using javassist
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6.2   Edit
Hardware: PC Windows Vista
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-29 14:57 EDT by sagar CLA
Modified: 2011-06-29 15:23 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.