i have a program that uses javamail to retrieve messages from an exchange server using imap protocol then i process each messages that has been unseen.
Recently i have come across with the problem of the program throwing a nullpointerexception i know that this is do to a unitialized object that is invoking a method, but in this case it does not make any sense to me.
The stacktrace of the exception is as follows:
java.lang.NullPointerException
at com.sun.mail.imap.IMAPFolder.handleResponse(IMAPFolder.java:1905)
at com.sun.mail.iap.Protocol.notifyResponseHandlers(Protocol.java:135
at com.sun.mail.imap.protocol.IMAPProtocol.fetchBodyStructure(IMAPProtocol.java:617)
at com.sun.mail.imap.IMAPMessage.loadBODYSTRUCTURE(IMAPMessage.java:1027)
at com.sun.mail.imap.IMAPMessage.getContentType(IMAPMessage.java:321)
at javax.mail.internet.MimeBodyPart.isMimeType(MimeBodyPart.java:802)
at javax.mail.internet.MimeMessage.isMimeType(MimeMessage.java:851)
at ctt.mail.FileHandler.putFilesFromMail(FileHandler.java:75)
at ctt.mail.FileHandler.main(FileHandler.java:37)
aditionaly i've got the debug trace from the last processed message
A607 FETCH 202 (FLAGS)
* 202 FETCH (FLAGS (\Seen))
A607 OK FETCH completed.
A608 FETCH 202 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 202 FETCH (ENVELOPE ("Mon, 14 Jul 2014 15:33:56 +0100" "=?iso-8859-1?Q?GPESE_-_ Pr=E9=5FAviso_de_Expedi=E7=E3o?=" (("SRS0+83ffd8147b51e356=4J=solicitador.net=gpese#solicitador.net" NIL "SRS0+83ffd8147b51e356=4J=solicitador.net=gpese" "solicitador.net")) NIL NIL (("=?iso-8859-1?Q?RECE=C7=C3O_FICHEIROS_CTT_WINREG?=" NIL "cttwinreg" "ctt.pt")) (("caraujo#caso.pt" NIL "caraujo" "caso.pt")) NIL NIL "<1890939061.7011405348433043.JavaMail.gpese#solicitador.net>") INTERNALDATE "14-Jul-2014 15:33:58 +0100" RFC822.SIZE 6462)
A608 OK FETCH completed.
A609 FETCH 202 (BODYSTRUCTURE)
* 202 FETCH (BODYSTRUCTURE (("text" "plain" ("charset" "iso-8859-1") NIL NIL "quoted-printable" 0 0 NIL NIL NIL NIL)("text" "xml" ("name" "GPESE - GE_369515.xml") NIL "GPESE - GE_369515.xml" "base64" 5202 67 NIL ("attachment" ("filename" "GPESE - GE_369515.xml" "size" "3865" "creation-date" "Mon, 14 Jul 2014 14:33:58 GMT" "modification-date" "Mon, 14 Jul 2014 14:33:58 GMT")) NIL NIL) "mixed" ("boundary" "_002_18909390617011405348433043JavaMailgpesesolicitadornet_") NIL "pt-PT"))
* 24457 FETCH (FLAGS (\Seen))
* 24458 FETCH (FLAGS (\Seen))
* 24459 FETCH (FLAGS (\Seen))
* 24460 FETCH (FLAGS (\Seen \Recent))
* 24461 FETCH (FLAGS (\Seen \Recent))
* 24462 FETCH (FLAGS (\Seen \Recent))
A609 OK FETCH completed.
the line that is throwing the exception is in this case a debug line :
System.out.println("Mensagem n.ยบ " + i + " de " + (new InternetAddress()).toString(message[i].getFrom()) + " com o assunto " + message[i].getSubject() + " recebida em " + (new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")).format(message[i].getReceivedDate()) + ". Nova? " + msgFlags.contains(javax.mail.Flags.Flag.RECENT) + ". Tem attachments mixed? " + message[i].isMimeType("multipart/mixed") + ". Tem attachments alternative? " + message[i].isMimeType("multipart/alternative") + ". Tem attachments alternative? " + message[i].isMimeType("") + ". O mime type \351? " + message[i].getContentType());
So the problem in this case is in one of the message[i].isMimeType(); but from my experience the exception can be thrown from another method such as message[i].getFlags().
I've tested message[i] for null and it's not null, thats why i dont understand why the exception is been thrown.
Any help would be appreciated.
Thanks.
edit:
Some additional stack trace exception that i have collected
java.lang.NullPointerException
at com.sun.mail.imap.IMAPFolder.handleResponse(IMAPFolder.java:1905)
at com.sun.mail.iap.Protocol.notifyResponseHandlers(Protocol.java:135)
at com.sun.mail.imap.protocol.IMAPProtocol.fetchFlags(IMAPProtocol.java:745)
at com.sun.mail.imap.IMAPMessage.loadFlags(IMAPMessage.java:1093)
at com.sun.mail.imap.IMAPMessage.getFlags(IMAPMessage.java:704)
at ctt.mail.FileHandler.putFilesFromMail(FileHandler.java:58)
java.lang.NullPointerException
at com.sun.mail.imap.IMAPFolder.handleResponse(IMAPFolder.java:1905)
at com.sun.mail.imap.IMAPFolder.handleResponses(IMAPFolder.java:1926)
at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:985)
at com.sun.mail.imap.IMAPMessage.getReceivedDate(IMAPMessage.java:278)
at ctt.mail.FileHandler.putFilesFromMail(FileHandler.java:63)
What version of JavaMail are you using? It looks like the NullPointerException is occurring in the JavaMail IMAP provider. From the stack trace it looks like this might be a very old version of JavaMail.
Related
I would like to understand why a variable of type com.ibm.jms.JMSTextMessage is printed with truncated content and ellipses (...) when converted to string.
I have this code in a JSR223 Sampler in JMeter:
import com.ibm.msg.client.jms.JmsConnectionFactory
import com.ibm.msg.client.jms.JmsFactoryFactory
import com.ibm.msg.client.wmq.WMQConstants
import javax.jms.Session
import javax.jms.TextMessage
def hostName = "127.0.0.1"
def hostPort = 1414
def channelName = "DEV.APP.SVRCONN"
def queueManagerName = "QM1"
def queueName = "DEV.QUEUE.1"
def ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER)
def cf = ff.createConnectionFactory()
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, hostName)
cf.setIntProperty(WMQConstants.WMQ_PORT, hostPort)
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channelName)
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT)
def connInboundQueue = cf.createConnection("user", "password")
def sessInboundQueue = connInboundQueue.createSession(false, Session.AUTO_ACKNOWLEDGE)
def payload = "AAA:+.? '\n" +
"ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'\n" +
"DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'\n" +
"GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'\n" +
"JKL+745'\n" +
"HHH+TN:IIAA891011213531235BNM422244:::001'\n" +
"CCC+NT+++ABCDEFGHIJKLMNOPQRS'\n" +
"STU+00123456789012:UF+0000000000:GY'\n" +
"VXY+50+MI1234+++MI'\n" +
"AAA+235+ABC'\n" +
"BBB+200:3202062000:301'\n" +
"FFF+90+USA'\n" +
"BBB+232:2101051135:201'\n" +
"CCC+FF+++AaBaBa001:TEST1'\n" +
"DDD+3++G'\n" +
"EEE+329:711013'\n" +
"FFF+178+XXX'\n" +
"FFF+179+YYY'\n" +
"GGG+2+ZZZ'\n" +
"HHH+BXG:ABCDEF'\n" +
"HHH+ABC:12AB3E01234E8UD8'\n" +
"III+P:110:111+100000001'\n" +
"EEE+36:281105'\n" +
"FFF+91+ASD'\n" +
"VVV+50:2'\n" +
"XXX+0011+1'\n" +
"YYY+1+U0123456'\n" +
"ZZZ+1+U1234560002'\n"
TextMessage msg = sessInboundQueue.createTextMessage()
msg.setText(payload)
log.info(msg.toString())
log.info(msg.getClass().toString())
log.info(msg.getText())
I would like to understand why log.info(msg.toString()) does not print the whole text content and show ellipses after some point (...)
If I do log.info(msg.getText()), I can see the whole text message.
Here is the print outcome in jmeter's console:
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue:
JMSMessage class: jms_text
JMSType: null
JMSDeliveryMode: 2
JMSDeliveryDelay: 0
JMSDeliveryTime: 1635710725481
JMSExpiration: 0
JMSPriority: 4
JMSMessageID: ID:414d5120514d312020202020202020201f537d6101c31040
JMSTimestamp: 1635710725481
JMSCorrelationID: 1757416553
JMSDestination: queue:///DEV.QUEUE.1
JMSReplyTo: null
JMSRedelivered: false
JMSXAppID: 4.1\bin\ApacheJMeter.jar
JMSXDeliveryCount: 0
JMSXUserID: mquser1
JMS_IBM_PutApplType: 28
JMS_IBM_PutDate: 20211031
JMS_IBM_PutTime: 20052548
AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:20 ...
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: class com.ibm.jms.JMSTextMessage
2021-10-31 22:05:25,491 INFO o.a.j.p.j.s.J.JSR223 Sampler - Producer - Inbound Queue: AAA:+.? '
ABC+ABCD:1+ABCDEFG:ZZ+ABCDEF:ZZ+123456:2042+12345678901++ABCD'
DEF+ABCD+LH+FVKJUB+20000:2042+Y1234567+UN+D:21B'
GHI+1+ABCD:D:11A:AA:ABCD+ABCD12345678901123ABC123456'
JKL+745'
HHH+TN:IIAA891011213531235BNM422244:::001'
CCC+NT+++ABCDEFGHIJKLMNOPQRS'
STU+00123456789012:UF+0000000000:GY'
VXY+50+MI1234+++MI'
AAA+235+ABC'
BBB+200:3202062000:301'
FFF+90+USA'
BBB+232:2101051135:201'
CCC+FF+++AaBaBa001:TEST1'
DDD+3++G'
EEE+329:711013'
FFF+178+XXX'
FFF+179+YYY'
GGG+2+ZZZ'
HHH+BXG:ABCDEF'
HHH+ABC:12AB3E01234E8UD8'
III+P:110:111+100000001'
EEE+36:281105'
FFF+91+ASD'
VVV+50:2'
XXX+0011+1'
YYY+1+U0123456'
ZZZ+1+U1234560002'
According to the IBM documentation com.ibm.jms.JMSTextMessage inherits the toString() implementation from com.ibm.jms.JMSMessage and the JavaDoc for that method says:
Gets a String containing a formatted version of the message header.
My guess is that the body is cut off simply because toString() is really just meant to give you the header. However, only IBM would know for sure why it works that way. To be clear, there is no guarantee that toString() will (or should) return the entire body of the message.
If you really want to inspect the body of the text message you should invoke getText(). This method is required to return the body of the text-message according to the JMS JavaDoc as well as IBM's own JavaDoc. Both state:
Gets the String containing this message's data. The default value is null.
Dears,
I have this code: (Move.java)
public void execute(ArrayList<Move> performedMoves) {
logger.debug(Thread.currentThread().getName() + " executing: from: " + from.getX() + ", " + from.getY() + " -> "
+ to.getX() + ", " + to.getY() + " p: " + piece.getShortDebug() + "->" + piece.executed + ", "
+ piece.rollbacked + ";" + "|" + piece.getCurrentPlace().getX() + ", "
+ piece.getCurrentPlace().getY());
if (executed && !rollbacked) {
throw new RuntimeException("this shouldn't be...");
}
//(more code)
from.remove(piece); // line 111, throwing the exception
to.setPiece(piece);
piece.setCurrentPlace(to);
And this is the log:
2021-03-07 11:12:57 DEBUG Move:195 - Thread-3 rollBack: from: 0, 2 -> 1, 2 p: t->true, false|0, 2
2021-03-07 11:12:57 DEBUG Move:148 - Thread-3 rollBack: from: 2, 1 -> 1, 2 p: p->true, false|1, 2
2021-03-07 11:12:57 DEBUG Move:156 - Thread-3 false, false|1, 2
2021-03-07 11:12:57 DEBUG Move:168 - Thread-3 false, false|1, 2
2021-03-07 11:12:57 DEBUG Move:195 - Thread-3 rollBack: from: 2, 1 -> 1, 2 p: p->true, false|2, 1
Exception in thread "Thread-3" org.bamboomy.c44.board.IllegalPlaceException: this piece wasn't here :-( -> 2, 0 == 2, 9=>t->true, true
at org.bamboomy.c44.board.Place.remove(Place.java:190)
at org.bamboomy.c44.board.Move.execute(Move.java:111)
at org.bamboomy.c44.board.Robot$Agent.evaluate(Robot.java:753)
at org.bamboomy.c44.board.Robot$Agent.evaluate(Robot.java:772)
at org.bamboomy.c44.board.Robot$Agent.evaluate(Robot.java:772)
at org.bamboomy.c44.board.Robot$Agent.evaluate(Robot.java:772)
at org.bamboomy.c44.board.Robot$Agent.run(Robot.java:608)
at java.base/java.lang.Thread.run(Thread.java:834)
2021-03-07 11:12:58 DEBUG Robot:374 - 0:-1.7976931348623157E308
2021-03-07 11:12:58 DEBUG Robot:374 - 1:-1.7976931348623157E308
How come the stacktrace in the log is preceded by:
2021-03-07 11:12:57 DEBUG Move:195 - Thread-3 rollBack: from: 2, 1 -> 1, 2 p: p->true, false|2, 1
in stead of something like:
2021-03-07 11:12:57 DEBUG Move:195 - Thread-3 executing: from: 2, 1 -> 1, 2 p: p->true, false|2, 1
(the log entry just before the exception is thrown)?
(the "rollback" debug entry is done in another method in the same class)
also:
if for some synchronisation issue for example this log entry is swallowed (I presume it's something like that): how can I force or flush the logger so I can have the output of that debug message?
It's very valuable information and it would help me a lot in debugging a complex problem...
Thanks for reading/pointers...
S.
edit: I use log4j 1.2.17
and the logger is inited like this:
final static Logger logger = Logger.getLogger(Move.class);
That output is sent directly to System.err via the Thread::getUncaughtExceptionHandler.
Per OpenJDK ThreadGroup::uncaughtException
public void uncaughtException(Thread t, Throwable e) {
if (parent != null) {
parent.uncaughtException(t, e);
} else {
Thread.UncaughtExceptionHandler ueh =
Thread.getDefaultUncaughtExceptionHandler();
if (ueh != null) {
ueh.uncaughtException(t, e);
} else if (!(e instanceof ThreadDeath)) {
System.err.print("Exception in thread \""
+ t.getName() + "\" ");
e.printStackTrace(System.err);
}
}
}
This code is bypassing your logging framework and printing directly to System.err when an uncaught exception is thrown and escapes the run method of the current thread.
If you want the code to contain a timestamp you have to do one of the following:
Implement a Thread.UncaughtExceptionHandler which logs to your logging framework. Then attach it to the all threads or a subset of threads when your application starts. Keep in mind that in environments with complex classloader structures this handler can pin the classloader and cause a memory leak. Good code hygiene would be to remove these handlers when your application is going to be shutdown.
In your runnable or callable implementation catch Throwable and log it to your logging framework.
I have been experimenting with bumping my applications dependency on PDFBox to the 2.0.0 snapshot.
I'm having some major issues with it though...
So my code recieves a PDF as a BASE64 String, i decode it, and load the resulting bytearray into a PDDocument. Before I bumped the version number, calling .silentPrint();on the PDDocument worked like a charm.
The implementation of silent printing changed in 2.0.0, and I now do it this way:
private Status doPdfPrint(Document document, PrintService printService) {
ByteArrayInputStream bais = null;
PDDocument doc = null;
PrinterJob printerJob = PrinterJob.getPrinterJob();
try {
printerJob.setPrintService(printService);
bais = new ByteArrayInputStream(document.getDecodedData());
doc = PDDocument.load(bais, true); //Force load
PDFPrinter pdfPrinter = new PDFPrinter(doc);
pdfPrinter.silentPrint(printerJob);
doc.close();
bais.close();
} catch (IOException | PrinterException e) {
log.warn("Failed to print! Exception occurred: {}", e.getMessage());
log.debug("EXCEPTION", e);
return Status.PRINTING_FAILED;
} finally {
IOUtils.closeQuietly(bais);
IOUtils.closeQuietly(doc);
}
return Status.PRINTING_OK;
}
However, when running this on OSX Yosemite, this results in:
2015-02-12 08:10:44.475 java[20264:1353636] Cocoa AWT: Not running on AppKit thread 0 when expected. (
0 libosxapp.dylib 0x0000000125997782 +[ThreadUtilities getJNIEnv] + 38
1 libawt_lwawt.dylib 0x000000012bf3004d syncFromJavaPixels + 1842
2 libawt_lwawt.dylib 0x000000012bf304e3 LockImage + 75
3 libawt_lwawt.dylib 0x000000012bf43040 Java_sun_java2d_CRenderer_doImage + 170
4 ??? 0x0000000108c15694 0x0 + 4441855636
5 ??? 0x0000000108c0798d 0x0 + 4441799053
)
2015-02-12 08:10:44.475 java[20264:1353636] Please file a bug report at http://java.net/jira/browse/MACOSX_PORT with this message and a reproducible test case.
2015-02-12 08:10:44.478 java[20264:1353636] java.lang.StackOverflowError
at sun.java2d.CRenderer.doImage(Native Method)
at sun.java2d.OSXSurfaceData.blitImage(OSXSurfaceData.java:1027)
at sun.java2d.CRenderer.blitImage(CRenderer.java:461)
at sun.java2d.CRenderer.scaleImage(CRenderer.java:455)
at sun.java2d.CRenderer.transformImage(CRenderer.java:508)
at sun.java2d.CRenderer.transformImage(CRenderer.java:582)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3461)
at sun.print.ProxyGraphics2D.drawImage(ProxyGraphics2D.java:1315)
at org.apache.pdfbox.rendering.PageDrawer.drawBufferedImage(PageDrawer.java:755)
at org.apache.pdfbox.rendering.PageDrawer.drawImage(PageDrawer.java:719)
at org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:51)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:802)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:464)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:438)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149)
at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:160)
at org.apache.pdfbox.rendering.PDFRenderer.renderPage(PDFRenderer.java:203)
at org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:166)
at org.apache.pdfbox.printing.PDFPrinter$PDFPrintable.print(PDFPrinter.java:430)
at sun.lwawt.macosx.CPrinterJob$4.run(CPrinterJob.java:653)
at sun.lwawt.macosx.CPrinterJob.printToPathGraphics(CPrinterJob.java:667)
at sun.lwawt.macosx.CPrinterJob.printLoop(Native Method)
at sun.lwawt.macosx.CPrinterJob.print(CPrinterJob.java:303)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1323)
at org.apache.pdfbox.printing.PDFPrinter.print(PDFPrinter.java:250)
at org.apache.pdfbox.printing.PDFPrinter.silentPrint(PDFPrinter.java:182)
at com.memnon.printr.PrintHandler.doPdfPrint(PrintHandler.java:123)
at com.memnon.printr.PrintHandler.print(PrintHandler.java:87)
at com.memnon.printr.PrintHandler.print(PrintHandler.java:77)
at com.memnon.printr.PrintHandler.print(PrintHandler.java:48)
at com.memnon.printr.communication.DocumentResponseHandler.handleSuccessful(DocumentResponseHandler.java:78)
at com.memnon.printr.communication.DocumentResponseHandler.handle(DocumentResponseHandler.java:53)
at com.memnon.printr.messaging.PrintConsumer.executePrinterJob(PrintConsumer.java:62)
at com.memnon.printr.messaging.PrintConsumer.run(PrintConsumer.java:44)
at java.lang.Thread.run(Thread.java:745)
2015-02-12 08:10:44.493 java[20264:1353636] NSAlert is being used from a background thread, which is not safe. This is probably going to crash sometimes. Break on void _NSAlertWarnUnsafeBackgroundThreadUsage() to debug. This will be logged only once. This may break in the future.
2015-02-12 08:10:46.639 java[20264:1353636] Apple AWT Internal Exception: Printing failed because PMSessionEndDocumentNoDialog() returned -30871.
2015-02-12 08:10:46.639 java[20264:1353636] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Printing failed because PMSessionEndDocumentNoDialog() returned -30871.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8895c66c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff890e876e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8895c51d +[NSException raise:format:] + 205
3 AppKit 0x00007fff8d117e80 -[NSPrintSpoolingGraphicsContext dealloc] + 43
4 libobjc.A.dylib 0x00007fff890fb89c _ZN11objc_object17sidetable_releaseEb + 236
5 libobjc.A.dylib 0x00007fff890e1e8f _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 575
6 CoreFoundation 0x00007fff88834302 _CFAutoreleasePoolPop + 50
7 libawt_lwawt.dylib 0x000000012bf25fa4 Java_sun_lwawt_macosx_CPrinterJob_printLoop + 165
8 ??? 0x0000000108c15694 0x0 + 4441855636
9 ??? 0x0000000108c07160 0x0 + 4441796960
10 ??? 0x0000000108c0798d 0x0 + 4441799053
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any idea what's going on?
Regards
So I'm posting here 2 years after this occured for the first time..
It's still occuring. However, it's a Java bug, rather then a PDFBox bug. So after filing my bugreport on PDFBox issue-tracker, I got the advice to set a DPI for the document when doing printing. And voila it works. However, it's nearly impossible to figure out the DPI of a pdf document.
However, if you know what the DPI is, you can simply do this:
final int rasterizedDpi = 203;
final PDDocument pdfDocument = PDDocument.load(data);
final PrinterJob job = PrinterJob.getPrinterJob();
final PDFPageable pageable = new PDFPageable(pdfDocument, Orientation.AUTO, false, rasterizedDpi);
job.setPageable(pageable);
job.print();
The hint here is the 4th argument to PDFPageable, the dpi...
Until Oracle fixes this JDK bug, i guess we're going to have to call this method :)
I'm debugging J2ME (written in eclipse) code on nokia N95 (wasn't written by me) trying to find error and printing out stacktrace gave me this:
03:08:479 TSKR. Error:
java.lang.NullPointerException: 0
- java.lang.String.<init>(), bci=6
- v.b(), bci=9
- v.e(), bci=805
- v.e(), bci=3
Could anyone please help me to understand that? Which line , where to look for and is there a way to understand it or at least get some valuable and usefull information.
Thank you
UPDATE
Sorry.. Here's the function that throws error:
public void bluetoothFileProcessBytes(){//--------tracing out of memory error
try{
partCurrentLoop++;
fileCurrentLoop++;
debug("Loop " + fileCurrentLoop + " of " + fileTotalLoops);
bluetoothUpdateBytes(fileDataString.length());
guiUpdateProgressBar(true, partCurrentLoop, partTotalLoops);
// LOOP Step 2: If there is no byte[] created for storing the bytes, create it.
if (fileBytesIsEmpty) {
if (partCurrentNumber == partTotalNumber)
{
fileBytes = new byte[fileSize % (loopsPerHttpComm * BYTES_PER_LOOP)];
}
else fileBytes = new byte[loopsPerHttpComm * BYTES_PER_LOOP];
}
fileBytesIsEmpty = false;
//LOOP Step 3: fill in the byte array with data from StringBuffer
for (int i = 0; i < fileDataString.length(); i++)
{
j = i + (partCurrentLoop - 1) * BYTES_PER_LOOP;
c = fileDataString.charAt(i);
fileBytes[j] = (byte) c;
}
c=0;
j=0;
i=0;
//LOOP Step 4: Send the email if the byte array is full with a new HttpComm Thread
if ((fileCurrentLoop % loopsPerHttpComm == 0
|| fileCurrentLoop == fileTotalLoops) && checkHttpCommStatus()) {
// update partName and httpCommStatus
String partName = fileName + " .part " + partCurrentNumber;
httpCommStatus = HTTP_RUNNING;
if (fileCurrentLoop == fileTotalLoops) { // FILE_END
debug("New HttpComm Thread: FILE END");
httpCommUpdateBytes(fileBytes.length);//<===================remove
httpCommSucceeded();//<====================================remove
/*new Thread(new HttpFileEnd(this, fileBytes, toAddress, fromAddress, fromName, digidownMAC, partName, fileName, fileSize, digidownSoftwareVersion, partCurrentNumber, //<===============uncomment
partTotalNumber, DigidownApp.textObject.getActiveLanguage())).start();*/
} else { // FILE_PART
//debug("Step 5");//<--------------------------------------------------------------------------------<-remove
debug("New HttpComm Thread: FILE PART: " + partName);
debug(">>>>>SEEEENDIIIING!<<<<<<<<");//<===========remove
httpCommUpdateBytes(fileBytes.length);//<================remove
httpCommSucceeded();//<==============================remove
/*new Thread(new HttpFilePart(this, fileBytes, toAddress, fromAddress, fromName,//<===============uncomment
digidownMAC, partName, fileSize, digidownSoftwareVersion,
partCurrentNumber, DigidownApp.textObject.getActiveLanguage())).start();*/
// Updating the new partTotalLoops
if (partCurrentNumber == partTotalNumber){
partTotalLoops = fileTotalLoops - (loopsPerHttpComm * (partCurrentNumber - 1));
} else partTotalLoops = loopsPerHttpComm;
partCurrentNumber++;
partCurrentLoop = 0;
}
fileBytesIsEmpty = true;
}
// Leave the loop if failed
if (!errorHandlerActivated) {
if (fileCurrentLoop < fileTotalLoops)
{
try{
bluetoothIOStream.getFileBytes();//-throws null pointer exception !
}catch(RuntimeException ea){debug("Wammaaa!!! " + ea.toString());
ea.printStackTrace();}
}
else if(fileCurrentLoop == fileTotalLoops && checkHttpCommStatus())
{ bluetoothIOStream.getFileEnd(); }
}
}
catch(RuntimeException e1)
{
Alert alert = new Alert("Fckn error!", e1.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
debug("Error:");
System.err.println();
e1.printStackTrace();
//throw e1;
}
}
..and the stack trace of unobfuscated app; this time it was null pointer exception after
// Leave the loop if failed:
02:57:382 TSKR. Loop 972 of 1349
02:57:383 BIOS. Rec 978
02:57:588 TSKR. Loop 973 of 1349
02:57:590 BIOS. Rec 979
02:57:815 TSKR. Wammaaa!!! java.lang.NullPointerException: 0
java.lang.NullPointerException: 0
- java.lang.String.<init>(), bci=6
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.readLineAsString(), bci=9
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=844
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getFileBytes(), bci=3
- net.digidown.m.digidown.TaskRunner.bluetoothFileProcessBytes(), bci=430
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=857
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getFileBytes(), bci=3
- net.digidown.m.digidown.TaskRunner.bluetoothFileProcessBytes(), bci=430
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=857
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getFileBytes(), bci=3
- net.digidown.m.digidown.TaskRunner.bluetoothFileProcessBytes(), bci=430
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=857
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getFileBytes(), bci=3
- net.digidown.m.digidown.TaskRunner.bluetoothFileProcessBytes(), bci=430
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=857
Goes like that for a while and then..:
- net.digidown.m.digidown.TaskRunner.bluetoothDoCommand_file(), bci=227
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=829
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getFileSettings(), bci=9
- net.digidown.m.digidown.TaskRunner.bluetoothTask(), bci=90
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=513
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getTask(), bci=2
- net.digidown.m.digidown.TaskRunner.bluetoothTask(), bci=172
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=513
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getTask(), bci=2
- net.digidown.m.digidown.TaskRunner.bluetoothConnected(), bci=89
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=444
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.getVariable(), bci=426
- net.digidown.m.digidown.bluetooth.BluetoothIOStream.run(), bci=366
- java.lang.Thread.run(), bci=11
03:01:211 TSKR. Finished Task
03:01:212 BIOS. Rec 6
03:01:356 BIOS. task = >
03:01:357 TSKR. :: Got Task: (0x3e)
03:01:358 TSKR.
03:01:359 TSKR. ERROR HANDLER: 116 - Bluetooth communication error
03:01:389 BIOS. Initiated
03:01:389 BIOS. About to read
03:01:394 BIOS. Phone(InitiateDigidownError) received: '0x3e 0xea Data CK'
03:01:397 BIOS. About to writeLine 'error'
03:01:468 BIOS. quitStatus = QUIT_STATUS
Your problem seems to be obfuscation.
The build process of your eclipse application probably uses a tool like proguard to increase the performance and decrease the size of the application .jar file that will be deployed in the field.
One of the thing obfuscation does is rewrite class and method names into much smaller names, hence the completely unintelligible last 3 lines of your stack trace.
You need to produce an unobfuscated .jar file to use when you want to debug your application.
(at least until you find an issue that only happens on the obfuscated version of your application. it happens)
Eclipse should allow you to turn obfuscation off (or reduce it to its lowest level) by modifying your project properties. Failing that, manually and temporarily hacking the ant .xml files used to build your .jar file will do the trick.
Obfuscation parameters should include the name of your MIDlet class so that its startApp() method is not renamed.
Your problem may be solve in two ways:
Run your application without obfuscation. So the output shows exact method names.
Put System.out.println('method_name::sample_tag') in your method and lines that the problem may be from them. Then in the output you can trace your execution and you can find the point that the problem occurs.
This is in continuation to a question I posted yesterday ( a link), for its asnwer I am greatful - undoubtly it solved a barrier.
Following the advice I removed the static modifiers. This, indeed, solved the issue of accumulated changes to the records. However, when I returned from the simplified application, built for the issue debugging, to the original environment, I noticed that adding a record still cause modification of the previous records. I assume it is something wrong I am doing with the ArrayList.
I simplified the application by removing all static, final and synchronized modifiers (regardless of its relevance to the problem) and still have the problem.
I narrowed the issue to the add method brought below. The method is called by the constructor of the data repository with test records with incremental ID field and various values of other fields.
private ArrayList<taskDef> tasksTable = new ArrayList<taskDef>();
public void addTask (taskDef newRecord)
{ // Add the record at the array's end
Boolean f = tasksTable.add(newRecord);
System.out.println( "\n>************** storing record (index " + (getTasksTableLength () - 1) +
")\tProject: " + tasksTable.get(getTasksTableLength () - 1).getProjectNumber() +
"\tID: " + tasksTable.get(getTasksTableLength () - 1).getId() +
"\ttable size: " + getTasksTableLength () + "\tsuccess: " + f +
"\tLog: " + tasksTable.get(getTasksTableLength () - 1).getLog());
if (getTasksTableLength () > 1)
System.out.println( ">************** Previous record (index " + (getTasksTableLength () - 2) + "): " +
"\tProject: " + tasksTable.get(getTasksTableLength () - 2).getProjectNumber() +
"\tID: " + tasksTable.get(getTasksTableLength () - 2).getId() +
"\tLog: " + tasksTable.get(getTasksTableLength () - 2).getLog());
}
In the log we can see that whenever a record is added the previous tasks are changed. The following printout shows only one previous record, but actually all previous records are being modified
>************** storing record (index 0) Project: P1000 ID: 1 table size: 1 success: true Log:
11/07/2012 07:14:02: ; project number (P1000); task (Task 1); task ID (1); owner (O1); status (started)
>************** storing record (index 1) Project: P1000 ID: 2 table size: 2 success: true Log:
11/07/2012 07:14:41: ; task (Task 2); task ID (2); delivery flag (true)
>************** Previous record (index 0): Project: P1000 ID: 1 Log:
11/07/2012 07:14:41: ; task (Task 2); task ID (2); delivery flag (true)
>************** storing record (index 2) Project: P1000 ID: 3 table size: 3 success: true Log:
11/07/2012 07:16:08: ; task (Task 3); task ID (3); owner (O2)
>************** Previous record (index 1): Project: P1000 ID: 2 Log:
11/07/2012 07:16:08: ; task (Task 3); task ID (3); owner (O2)