[pylucene-dev] weird exception java.lang.ClassCastException
Andi Vajda
vajda at osafoundation.org
Sat Feb 5 14:16:55 PST 2005
No, it's working as expected. The SWIG wrapper wraps a ScoreDoc even though it
actually is a FieldDoc because it is declared to be a ScoreDoc. Because of
that, I added a bunch of downcasting and dynamic type checking extension
method to the SWIG wrappers over time. As a matter of fact, the ScoreDoc ->
FieldDoc downcasting API, I just added this morning.
Check PyLucene.i for is<Class>() and to<Class>() extension methods.
For example: if scoreDoc.isFieldDoc():
fieldDoc = scoreDoc.toFieldDoc()
Andi..
On Sat, 5 Feb 2005, Yura Smolsky wrote:
> Hello, Andi.
>
> hmm. I am in the next issue :)
> print fDoc , where fDoc = [FieldDoc|ScoreDoc] says:
>
> org.apache.lucene.search.FieldDoc at fc6e40
>
> but when I try to do
> print fDoc.fields
>
> it says "there is no attribute for ScoreDoc object"..
>
> Something wrong about types?
>
>
> AV> That you dynamically check the type of the instances you serialize.
>
> AV> Andi..
>
> AV> On Sat, 5 Feb 2005, Yura Smolsky wrote:
>
>>> Hello, Andi.
>>>
>>> Well, what do you suggest? ;)
>>>
>>> AV> FieldDoc is a subclass of ScoreDoc. If the java code expects that the
>>> AV> scoreDocs array in the TopFieldDocs instance, which is declared as
>>> AV> ScoreDoc[], is actually containing FieldDoc instances and if that fact gets
>>> AV> lost during serialization/deserialization, then you get exactly that error
>>> AV> when java downcasts the ScoreDoc instance to a FieldDoc.
>>>
>>> AV> Basically, I'm saying that you cannot statically expect the scoreDocs array in
>>> AV> a TopFieldDocs instance to contain just ScoreDoc instances, it actually tends
>>> AV> to contain FieldDoc instances, which is legal since FieldDoc is a subclass of
>>> AV> ScoreDoc.
>>>
>>> AV> Andi..
>>>
>>> AV> On Sat, 5 Feb 2005, Yura Smolsky wrote:
>>>
>>>>> Hello, Yura.
>>>>>
>>>>> I have found that problem is about initialization of ScoreDoc object.
>>>>> When I use existent ScoreDoc object created by java then everything is
>>>>> okay. When I use ScoreDoc object created in python -> it produces
>>>>> exception.
>>>>>
>>>>> Check new attach.
>>>>>
>>>>> YS> Hello, Andi.
>>>>>
>>>>> YS> I just have added TopFieldDocs manual creation code. This code does
>>>>> YS> recreate TopFieldDocs object using PyLucene classes ScoreDoc,
>>>>> YS> SortField and TopFieldDocs. Check attached file.
>>>>> YS> This example returns exeption:
>>>>>
>>>>> YS> D:\workshop\blogz-src>d:\work\python24\python.exe RemoteSearch2.py
>>>>> YS> in searchSorted
>>>>> YS> ['"modified"!']
>>>>> YS> 249 1.0
>>>>> YS> 269 0.282842695713
>>>>> YS> 4 0.34999999404
>>>>> YS> 52 0.17499999702
>>>>> YS> modified 3 True
>>>>> YS> in searchSorted, finished
>>>>> YS> Exception in thread "MultiSearcher thread #1"
>>>>> YS> java.lang.ClassCastException:
>>>>> org.apache.lucene.search.ScoreDoc
>>>>> YS> cannot be cast to
>>>>> YS> org.apache.lucene.search.FieldDoc
>>>>> YS> *** Got java.lang.NullPointerException while trying to print stack trace.
>>>>> YS> 4
>>>>>
>>>>> AV>> I verified, by modifying the RemoteSearcher.py code you sent me yesterday that
>>>>> AV>> 'searchSorted' is working properly. The code is attached.
>>>>>
>>>>> AV>> Andi..
>>>>>
>>>>> AV>> On Sat, 5 Feb 2005, Yura Smolsky wrote:
>>>>>
>>>>>>>> Hello, pylucene-dev.
>>>>>>>>
>>>>>>>> I use ParallelMultiSearcher and I construct manually variables passed
>>>>>>>> to search, searchSorted methods of Searchable implementation.
>>>>>>>> I got this exception when I use sort and ParallerMultiSearcher:
>>>>>>>>
>>>>>>>> scoreDoc: 261
>>>>>>>> scoreDoc: 211
>>>>>>>> ... skipped ...
>>>>>>>> scoreDoc: 142
>>>>>>>> scoreDoc: 144
>>>>>>>> Exception in thread "MultiSearcher thread #1"
>>>>>>>> java.lang.ClassCastException:
>>>>>>>> org.apache.lucene.search.ScoreDoc
>>>>>>>> cannot be cast to
>>>>>>>> org.apache.lucene.search.FieldDoc
>>>>>>>> at 0x012ce0ae (Unknown Source)
>>>>>>>> ... skipped
>>>>>>>> hits: 18
>>>>>>>>
>>>>>>>> if I do not use sort or if I use Searchable implementation through
>>>>>>>> searchSorted then everything is ok.
>>>>>>>> I do not understand this.. Who is messing the data?..
>>>>>>>> Maybe method searchSorted of implementation of Searchable generates
>>>>>>>> "bad" PyLucene classes?..
>>>>>>>>
>>>>>>>> Thanks in advance.
>>>>>>>>
>>>>>>>> Yura Smolsky
>>>>> AV>>
>>>>>
>>>>>
>>>>>
>>>>> YS> Yura Smolsky,
>>>>> YS>
>>>>>
>>>>>
>>>>>
>>>>> Yura Smolsky,
>>>
>>>
>>>
>>> AV>
>>>
>>>
>>>
>>> Yura Smolsky,
>>>
>>>
>>>
>>>
>
>
>
> AV>
>
>
>
> Yura Smolsky,
>
More information about the pylucene-dev
mailing list