Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An error while loading class

 
Anirban Chatterjee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I need to find out if a class implements the java.io.Serializable interface .

For that I am reading in the class through a bytestream and loading it using class.defineClass() method.
And getting the interfaces by
loadedClass.getInterfaces();

Everything goes fine if its a standalone class.

But if this class extends another class , or implements a not system interface , I am getting a class loader exception .
Can any one help me out with this?
Anirban
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just try to Serialize it, and if it is not Serializable, handle the exception?
 
Anirban Chatterjee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cindy Glass:
Why don't you just try to Serialize it, and if it is not Serializable, handle the exception?

Hi,
Thanks for the suggestion .
But dont I have to load the class to try and serialize the same ?
Here is the use case for me >
I have a .class file which can be present in the file system , which I can basically read into an array of bytes .
I know the fully qualified name of the class as well .
How do I find out if it implements java.io.Serialisable in the easiest manner possible ?
Thanks in advance,
Anirban
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh - I get it now :roll: .
hmmm , the only isSerializable() that I know of is used in the Doclet stuff.
Nope - I am just not going to be able to help here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic