rrevo / com.onyem.jtracer.reader

0 stars 1 forks source link

Class name search by name throws Exception as it is not unique #2

Closed rrevo closed 11 years ago

rrevo commented 11 years ago

For the Guice sample, ClassDAO.getClassByName throws an exception since too many results were returned

java.lang.RuntimeException: Too many results
query=SELECT * FROM CLASSES C WHERE C.NAME = ? AND C.PACKAGE = ? AND C.IS_INTERFACE = ?
results=[
ClassImpl [id=29, metaId=null, access=null, classType=CLASS, className=Errors$Converter, packageName=com.google.inject.internal, superClass=null, interfaces=[], componentType=null, signature=null, canonicalName=Lcom/google/inject/internal/Errors$Converter;],
ClassImpl [id=32, metaId=187, access=1056, classType=CLASS, className=Errors$Converter, packageName=com.google.inject.internal, superClass=ClassImpl [id=10, metaId=null, access=null, classType=CLASS, className=Object, packageName=java.lang, superClass=null, interfaces=[], componentType=null, signature=null, canonicalName=Ljava/lang/Object;], interfaces=[], componentType=null, signature=<T:Ljava/lang/Object;>Ljava/lang/Object;, canonicalName=Lcom/google/inject/internal/Errors$Converter;],
results=]
at com.onyem.jtracer.reader.db.internal.JdbcHelper.queryForObject(JdbcHelper.java:129)
at com.onyem.jtracer.reader.meta.internal.dao.ClassDAO.getClassWithInterfaces(ClassDAO.java:117)
at com.onyem.jtracer.reader.meta.internal.dao.ClassDAO.getClassByName(ClassDAO.java:90)
....
rrevo commented 11 years ago

The issue was caused because the class was inserted first as part of an exception trace, Later the same class was inserted as part of the normal meta class loading. This causes an exception when the class was loaded by name.

Fix is to check if a class has been already partially inserted before during a normal insert.

rrevo commented 11 years ago

Fix to merge classes during insert was implemented in commit ad9933b0a7afe5a614d23d2314937e5a763f83a0

In revision 4c817dd31fa7845a119e049a45839cdd13dc7b69 IMethod and IClass do not directly store other IClass references. They store db references like ClassId. The intent to make this change was that mutations in objects would be difficult to update if the objects were directly stored. With references, a newer object can be obtained in the future. It does not solve all the problems related to incomplete information but reduces them. It also means that IMetaService becomes critical for clients.