We are getting a nullpointerexception at searchResponse.getHits().getHits();
I'm totally new to elastic search and don't know how it works but need to analyse this issue.
Let me know if it throws nullpointerexception in any case ?
If it throws how to handle this ?
Looking at the code of InternalSearchResponse, it looks like hits gets initialised with SearchHits.empty() even if the response is empty.
For the other cases, it always gets initialised with new. You can have a look at the source code here.
I had the same exception after an update from 7.4 to 7.17.
It seems that the hits variable of the internalResponse can be NULL, at least in 7.17.1 - could be related to HL request option ignoreUnavailable set to FALSE, and/or queering a no longer existing index.
searchResponse.getHits() can return NULL!
Related
EDIT: I'm using the LeanFT Java SDK 14.50
EDIT2: for text clarification
I'm writing test scripts for a web application that sometimes opens popup browsers for specific actions. So natually when that happens, I will attach the new browser using BrowserFactory.attach(...). The problem is that leanFT does not seem to have a way to validate that the browser exists before attaching it, and if I try to attach it too early, it will fail. And I don't like to use an arbitrairy wait/sleep time as I can never really know how much time it's going to take for the browser to get be ready. So my solution to this is below
private Browser attachPopUpBrowser(BrowserType bt, RegExpProperty url){
Browser browser = null;
int iteration = 0;
//TimeoutLimit.SHORT = 15000
while (browser == null && iteration < TimeoutLimit.SHORT.getLimit()) {
try {
Reporter.setReportLevel(ReportLevel.Off);
browser = BrowserFactory.attach(
new BrowserDescription.Builder()
.type(bt)
.url(url)
.build()
);
Reporter.setReportLevel(ReportLevel.All);
} catch (GeneralLeanFtException e) {
try {
Thread.sleep(1000);
iteration += 1000;
} catch (InterruptedException e1) {
}
}
}
return browser;
}
Now, this works wonderfully with one exception. It generates errors in the leanft test result. Errors that I want to ignore because I know that it will fail a few times before it will succeed. As you can see, I've tried changing the ReportLevel while doing this in order to suppress the error logging, but it doesn't work. I've tried using
Browser[] browsers = BrowserFactory.getallOpenBrowsers(BrowserDescription);
thinking that it will return an empty Array if it finds nothing, but I still get errors while the browser is not ready. Does anyone have suggestions as to how I could work around this?
TL;DR
I'm looking for a way to either suppress the errors generated within my While..Loop or to validate that the browser is ready before attaching it. All of that, so that I can have a nice and clean Run Result at the end of my test (because these errors will present false negatives in all nearly all of my tests)
Addendum
Also, when the attach fails for the first time, I get a an exception
com.hp.lft.sdk.ReplayObjectNotFoundException: attachApplication
as expected, but all subsequent failures are throwing
com.hp.lft.sdk.GeneralLeanFtException: Cannot read property 'match' of null
I've compared both stack traces and they are identical except for the last 2 lines which happen within the ReplayExceptionFactory.CreateDefault() so I think that there is something that gets corrupted during the exception generation, but that is within the leanft.sdk.internal package so there might not be a lot we can do about it right now.I'm guessing that if I did not get that second "cannot read property" exception, I would correctly get the ReplayObjectNotFoundException until the browser is correctly attached.
I'd rather not force an attach endlessly until it works. Even if we'd solve the false negatives, we'd still have a not so good approach to the problem.
The cleanest solution would be to see if there is anything to attach to in the first place.
And you can do just that by getting all the browser instances that meets your description.
Browser[] browsers = BrowserFactory.getAllOpenBrowsers(new BrowserDescription.Builder().build());
Any element in this collection is an already "attached" browser - you can start using it.
If the list doesn't contain your browser instance, rerun the query.
I am using the Eclipse MessageManager to provide error messages in case of invalid input. For example:
mmng.addMessage("textLength", "blah", null, IMessageProvider.ERROR, field);
I do this twice. Once inside an instance of ModifyListener and once just right after the creation of the Text field in order to validate input on load.
The MessageManager displays an error in the header of the page as well as next to the text field (decorator) when calling the addMessage method inside the modifyEvent method of an child instance of ModifyListener. However, when adding the message right after the creation of the text field, only a decorator will be displayed (no errors in the header saying that "n errors detected").
I am wondering why this happens. I tested this with the Eclipse ProductEditor and there's actually a similar behavior. The errors won't appear in the header if you open a .product file that has on the first page an error (only the decorator will appear). However, when switching to other pages and then switching back to this particular page, the error in the header will appear. Unfortunately, this is not the case on my side. I would be satisfied if I could implement the same behavior, even though the best case would be to automatically display errors on both locations, in the header and next to the field as a decorator.
I also tried to solve this issue by calling the update() method of the MessageManager instance, but unfortunately, that did not solve the mystery.
By the way, I am using Eclipse Luna 2.
I debugged the MessageManager class and noticed the following condition inside the update method:
if (form.getHead().getBounds().height == 0 || mergedList.isEmpty() || mergedList == null) {
form.setMessage(null, IMessageProvider.NONE);
return;
}
Besides that a NPE will be thrown when mergedList is null, this condition seems really strange to me. However, setting the height of head solved my problem:
form.getForm().getHead().setBounds(0, 0, 0, 1);
I want to persist a fix4.2 message to database by retrieving the value of each tag. I am having the ExecutionReport object of the fix message.
I am retrieving the tag value of account using exec.getString(1) and this tag value is not present in the message so it is throwing FieldNotFound exception.
In Fiximate I found that account is not a mandatory field.
I also tried with exec.getAccount().getValue() but got same exception.
I found that every all these method throws FieldNotFound exception.
Is there any way to retrieve the tag value as null if that non-mandatory field is not present in the fix message.
Any help will be highly appreciated.
Thanks in advance.
Regards,
Shadab
You didn't say which QuickFIX port you are using (e.g. the original QF for C++, QF/J for Java, QF/n for C#).
If a field is not required, you simply need to test for its presence first.
C++: exec.isSetField(1) or exec.isSetField(field)
(there might also be a exec.isSetAccount(), not sure)
Java: exec.isSetField(1) or exec.isSetAccount() or exec.isSetField(field)
C#: exec.IsSet(1) or exec.IsSetAccount() or exec.IsSetField(field)
I got NullPointerException error after using toString().substring() . I need to use this method. Help me please. I am not very sure i can use that method inside the query.
Orginal
String selectItemMasDetl="select MMITNO,MMITDS,MMALUN,MMSPUN from"+DBConnect.SCHEMA+".mitmas where MMCONO=888 and MMITNO="+ItemNo+"'";
Use ToString().substring()
String selectItemMasDetl="select MMITNO,MMITDS,MMALUN,MMSPUN from"+DBConnect.SCHEMA+".mitmas where MMCONO=888 and MMITNO="+ItemNo.toString().substring(0,4)+"'";
error log
java.lang.NullPointerException
[12/13/11 16:24:28:594 SGT] a6cc007 SystemErr R at com.------erp.report.stocklotsalesreport.StockLotSalesReportGet.getItemMasDetl
ANS:
selectItmMas="select MMITNO,MMITDS,MMALUN,MMSPUN from "+DBConnect.SCHEMA+".mitmas where MMCONO=888 and MMITNO like '"+ salesRecordListTO.getItemNo().trim() +"%'";
I use like operator and pass parameter instead of using trim. Now i get the result i want.
Thank you so much guys.
It means that at least in some cases either ItemNo or, DBConnect or the returned value of the toString() (as suggested) is null. The problem is that you don't have a stack trace, and so you can't be sure where the error is thrown. It could be even on another line, for what we (don't) know now.
Try to wrap with a try catch the relevant lines and print a stack trace, check the line of code where is happening, and post here again. Here is how:
try {
//code throwing exception
} catch (Exception ex) {
ex.printStackTrace();
}
Side note: seems that you need a space after the from, also you're closing a single quote, but I don't see the opening. Below, for reference, your code, only reformatted, not fixed:
String selectItemMasDetl = "select MMITNO,MMITDS,MMALUN,MMSPUN from"
+ DBConnect.SCHEMA + ".mitmas where MMCONO=888 and MMITNO="
+ ItemNo.toString().substring(0,4) + "'";
NullPointerExeption means that ItemNo is null, so when trying to use ItemNo.toString(), it will be interpreted as null.toString() which will throw the exception.
A check on null is one possibility (the easiest), see answer of Stivlo.
Depending on how quick the query is a count query can be done also, if count ==0 don't bother to do the real query.
Oops, sorry, not reading good: the null exception is already in building the query string. Well maybe this is of use in your next nullpointer exception :)
StringBuilder might be a solution, but than I think you'll get an invalid querystring, just use Stivlo's answer.
I am trying to update content in Google sites and am reading the stream in exception VersionConflictException.
When I check the stream it is all fine and is completely loaded in POST request but then I get following error.
org.apache.commons.fileupload.FileItemStream$ItemSkippedException
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:880)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at com.google.gdata.data.media.MediaSource$Output.writeTo(MediaSource.java:87)
at com.google.gdata.data.media.MediaBodyPart$MediaSourceDataHandler.writeTo(MediaBodyPart.java:74)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:452)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:157)
at com.google.gdata.wireformats.output.media.MediaMultipartGenerator.generate(MediaMultipartGenerator.java:58)
at com.google.gdata.wireformats.output.media.MediaMultipartGenerator.generate(MediaMultipartGenerator.java:37)
at com.google.gdata.client.Service.writeRequestData(Service.java:1831)
at com.google.gdata.client.media.MediaService.updateMedia(MediaService.java:497)
at com.google.gdata.data.media.MediaEntry.updateMedia(MediaEntry.java:159)
at morefile.UploadApp.updateAttachment(UploadApp.java:136)
FileItemStream.ItemSkippedException
This exception is thrown, if an
attempt is made to read data from the
InputStream, which has been returned
by FileItemStream.openStream(), after
Iterator.hasNext() has been invoked on
the iterator, which created the
FileItemStream.
I don't want to wake the zombies - this is just for future reference.
This is a basically a bad implementation of the apache-commons-fileupload. Calling hasNext() should NEVER render the result of the last next() call invalid. E.g. you can't do something like this
List collection;
while(hasNext(){
Object o = next();
collection.add(o);
}
Because if you access any item in the list it will result in an ItemSkippedException.
I got the same problem. I found it was caused by calling 'Streams.asString( stream)' twice. Reviewing the file upload source code, Streams.asString() will close the stream at the end of its operation, so if you call it again with the same stream, which is InputStream obtained from FileItemStream.openStream() by the way, you will get this exception. Fixed my program, and it works now as I intended!
I used to get this when I used to close the stream during iteration. Don't close the stream and it works fine.
Here is what was happening to me. I was getting this error because I had added
FileItemStream.openStream()
to the "Add Watch" in Intellij Idea, which is why it was throwing me this error.
Don't add this to watch while debugging.