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 :)
Related
I am using C language Native API callbacks with DLL files. When we are calling callback first time everything is working fine but on second call I am getting heap corruption error and JVM is getting crashed.
In the native code the memory allocated in first call is being released and then is being used in second call again and during memory allocation in second call JVM is being crashed. But on the same place when in second call new memory pointer is used rather than the one which was used in previous call I am not getting this heap corruption error.
As this callback is called many times I can not keep on allocating new space every time. In below logs I am getting error as INVALID_POINTER_READ.
I am not able to understand what is the reason behind it and how this can be fixed. When same DLL is used with JNA it's working fine.
Java/JNA Code:
Setting Hook:
final PropertyCallBack callback = new PropertyCallBack();
final int setHookStatus = callback.setHook();
private static CALLBACK callback;
public int setHook() {
if (callback != null) {
return 0;
}
synchronized (this) {
if (callback == null) {
callback = new CALLBACK();
return callback.setHook();
}
}
return 0;
}
Callback Method Called From Native:
#Override
public int PropertyHook(final DESTINATION dest, final BACSTAC_READ_INFO.ByReference info) {
final PROPERTY_CONTENTS.ByReference content = new PROPERTY_CONTENTS.ByReference();
final BUFFER.ByReference buffer = new BUFFER.ByReference();
// Memory assign
final int bufferSize = 1048;
buffer.pBuffer = new Memory(bufferSize);
buffer.nBufferSize = bufferSize;
content.tag = "INVALID";
content.buffer = buffer;
content.nElements = 0;
Pointer dev = NativeLibrary.INSTANCE.Call_1();
Pointer obj = null;
if (dev != null) {
obj = NativeLibrary.INSTANCE.call_2(dev, info.objectID);
}
final int readDbStatus = NativeLibrary.INSTANCE.call_3(obj, info.prop, info.index, content, null);
final int responseStatus = NativeLibrary.INSTANCE.call_4(dest, info, content);
return 0;
}
When I analyzed heap dump with windbg I am getting below details:
This dump file has an exception of interest stored in it.
The stored exception information can be accessed via .ecxr.
(6201c.5ef10): Access violation - code c0000005 (first/second chance not available)
For analysis of this file, run !analyze -v
ntdll!NtWaitForMultipleObjects+0x14:
00007ffa`46deb4f4 c3 ret
0:026> !analyze -v
*******************************************************************************
* *
* Exception Analysis *
* *
*******************************************************************************
*** WARNING: Unable to verify checksum for srv.dll
DEBUG_FLR_EXCEPTION_CODE(c0000374) and the ".exr -1" ExceptionCode(c0000005) don't match
KEY_VALUES_STRING: 1
Key : AV.Fault
Value: Read
Key : Timeline.Process.Start.DeltaSec
Value: 46
PROCESSES_ANALYSIS: 1
SERVICE_ANALYSIS: 1
STACKHASH_ANALYSIS: 1
TIMELINE_ANALYSIS: 1
Timeline: !analyze.Start
Name: <blank>
Time: 2019-12-02T11:13:41.439Z
Diff: 3429439 mSec
Timeline: Dump.Current
Name: <blank>
Time: 2019-12-02T10:16:32.0Z
Diff: 0 mSec
Timeline: Process.Start
Name: <blank>
Time: 2019-12-02T10:15:46.0Z
Diff: 46000 mSec
DUMP_CLASS: 2
DUMP_QUALIFIER: 400
CONTEXT: (.ecxr)
rax=0000000000030000 rbx=000000002b200000 rcx=0000000000000303
rdx=0000000000000003 rsi=01fda8c00000ed00 rdi=000000002b223ef0
rip=00007ffa46d6cb7a rsp=000000002b8ff500 rbp=0000000000000008
r8=0000000000000028 r9=0000000000000030 r10=00000000014da2d0
r11=00000000014e2ef0 r12=0000000000000001 r13=0000000000000003
r14=000000002b223ee0 r15=000000000600c1ba
iopl=0 nv up ei pl zr na po nc
cs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010246
ntdll!RtlpAllocateHeap+0xdaa:
00007ffa`46d6cb7a 498b07 mov rax,qword ptr [r15] ds:00000000`0600c1ba=????????????????
Resetting default scope
FAULTING_IP:
ntdll!RtlpAllocateHeap+daa
00007ffa`46d6cb7a 498b07 mov rax,qword ptr [r15]
EXCEPTION_RECORD: (.exr -1)
ExceptionAddress: 00007ffa46d6cb7a (ntdll!RtlpAllocateHeap+0x0000000000000daa)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 0000000000000000
Parameter[1]: 000000000600c1ba
Attempt to read from address 000000000600c1ba
DEFAULT_BUCKET_ID: HEAP_CORRUPTION
PROCESS_NAME: javaw.exe
FOLLOWUP_IP:
ntdll!RtlpAllocateHeap+daa
00007ffa`46d6cb7a 498b07 mov rax,qword ptr [r15]
READ_ADDRESS: 000000000600c1ba
ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.
EXCEPTION_CODE: (NTSTATUS) 0xc0000374 - A heap has been corrupted.
EXCEPTION_CODE_STR: c0000005
EXCEPTION_PARAMETER1: 0000000000000000
EXCEPTION_PARAMETER2: 000000000600c1ba
WATSON_BKT_PROCSTAMP: 5d1dea24
WATSON_BKT_PROCVER: 8.0.2210.11
PROCESS_VER_PRODUCT: Java(TM) Platform SE 8
WATSON_BKT_MODULE: ntdll.dll
WATSON_BKT_MODSTAMP: 7f828745
WATSON_BKT_MODOFFSET: 1cb7a
WATSON_BKT_MODVER: 10.0.17134.799
MODULE_VER_PRODUCT: Microsoft® Windows® Operating System
BUILD_VERSION_STRING: 17134.1.amd64fre.rs4_release.180410-1804
MODLIST_WITH_TSCHKSUM_HASH: f06ad8a6a7f7267c783c08e3a62df4696020d52f
MODLIST_SHA1_HASH: cdafa8057ac19b1a3608c439ebbfa992407212d6
NTGLOBALFLAG: 0
PROCESS_BAM_CURRENT_THROTTLED: 0
PROCESS_BAM_PREVIOUS_THROTTLED: 0
APPLICATION_VERIFIER_FLAGS: 0
DUMP_FLAGS: 94
DUMP_TYPE: 1
ANALYSIS_SESSION_HOST: MD2E86EC
ANALYSIS_SESSION_TIME: 12-02-2019 16:43:41.0439
ANALYSIS_VERSION: 10.0.18362.1 x86fre
THREAD_ATTRIBUTES:
ADDITIONAL_DEBUG_TEXT: Enable Pageheap/AutoVerifer ; Followup set based on attribute [Is_ChosenCrashFollowupThread] from Frame:[0] on thread:[PSEUDO_THREAD]
FAULTING_THREAD: 0005ef10
THREAD_SHA1_HASH_MOD_FUNC: 5d531e271dfb1ef7af4984c7ee0dd671c07337f5
THREAD_SHA1_HASH_MOD_FUNC_OFFSET: d858fa5fb04738fbbbbb9e4df89e26d53dc74794
OS_LOCALE: ENU
BUGCHECK_STR: APPLICATION_FAULT_INVALID_POINTER_READ_HEAP_CORRUPTION
PRIMARY_PROBLEM_CLASS: APPLICATION_FAULT
PROBLEM_CLASSES:
ID: [0n262]
Type: [HEAP_CORRUPTION]
Class: Primary
Scope: DEFAULT_BUCKET_ID (Failure Bucket ID prefix)
BUCKET_ID
Name: Add
Data: Omit
PID: [0x6201c]
TID: [0x5ef10]
Frame: [0] : ntdll!RtlpAllocateHeap
ID: [0n262]
Type: [HEAP_CORRUPTION]
Class: Primary
Scope: BUCKET_ID
Name: Add
Data: Omit
PID: [0x6201c]
TID: [0x5ef10]
Frame: [0] : ntdll!RtlpAllocateHeap
ID: [0n313]
Type: [#ACCESS_VIOLATION]
Class: Addendum
Scope: BUCKET_ID
Name: Omit
Data: Omit
PID: [Unspecified]
TID: [0x5ef10]
Frame: [0] : ntdll!RtlpAllocateHeap
ID: [0n285]
Type: [INVALID_POINTER_READ]
Class: Primary
Scope: BUCKET_ID
Name: Add
Data: Omit
PID: [Unspecified]
TID: [0x5ef10]
Frame: [0] : ntdll!RtlpAllocateHeap
LAST_CONTROL_TRANSFER: from 00007ffa46d69725 to 00007ffa46d6cb7a
STACK_TEXT:
00000000`00000000 00000000`00000000 heap_corruption!javaw.exe+0x0
THREAD_SHA1_HASH_MOD: ca4e26064d24ef7512d2e94de5a93c38dbe82fe9
SYMBOL_STACK_INDEX: 0
SYMBOL_NAME: heap_corruption!javaw.exe
FOLLOWUP_NAME: MachineOwner
MODULE_NAME: heap_corruption
IMAGE_NAME: heap_corruption
DEBUG_FLR_IMAGE_TIMESTAMP: 0
STACK_COMMAND: ** Pseudo Context ** ManagedPseudo ** Value: a3807e8 ** ; kb
FAILURE_BUCKET_ID: HEAP_CORRUPTION_c0000005_heap_corruption!javaw.exe
BUCKET_ID: APPLICATION_FAULT_INVALID_POINTER_READ_HEAP_CORRUPTION_heap_corruption!javaw.exe
FAILURE_EXCEPTION_CODE: c0000005
FAILURE_IMAGE_NAME: heap_corruption
BUCKET_ID_IMAGE_STR: heap_corruption
FAILURE_MODULE_NAME: heap_corruption
BUCKET_ID_MODULE_STR: heap_corruption
FAILURE_FUNCTION_NAME: javaw.exe
BUCKET_ID_FUNCTION_STR: javaw.exe
BUCKET_ID_OFFSET: 0
BUCKET_ID_MODTIMEDATESTAMP: 0
BUCKET_ID_MODCHECKSUM: 0
BUCKET_ID_MODVER_STR: 0.0.0.0
BUCKET_ID_PREFIX_STR: APPLICATION_FAULT_INVALID_POINTER_READ_
FAILURE_PROBLEM_CLASS: APPLICATION_FAULT
FAILURE_SYMBOL_NAME: heap_corruption!javaw.exe
WATSON_STAGEONE_URL: http://watson.microsoft.com/StageOne/javaw.exe/8.0.2210.11/5d1dea24/ntdll.dll/10.0.17134.799/7f828745/c0000005/0001cb7a.htm?Retriage=1
TARGET_TIME: 2019-12-02T10:16:32.000Z
OSBUILD: 17134
OSSERVICEPACK: 753
SERVICEPACK_NUMBER: 0
OS_REVISION: 0
SUITE_MASK: 256
PRODUCT_TYPE: 1
OSPLATFORM_TYPE: x64
OSNAME: Windows 10
OSEDITION: Windows 10 WinNt SingleUserTS
USER_LCID: 0
OSBUILD_TIMESTAMP: unknown_date
BUILDDATESTAMP_STR: 180410-1804
BUILDLAB_STR: rs4_release
BUILDOSVER_STR: 10.0.17134.1.amd64fre.rs4_release.180410-1804
ANALYSIS_SESSION_ELAPSED_TIME: 307a
ANALYSIS_SOURCE: UM
FAILURE_ID_HASH_STRING: um:heap_corruption_c0000005_heap_corruption!javaw.exe
FAILURE_ID_HASH: {ddc2b378-b1e1-2aec-adc8-f11b7a5773a9}
Any help in fix/debug will be highly appreciated.
I got the solution of to prevent above heap corruption by calling NativeLibrary methods of PropertyHook in another thread. Somehow by calling NativeLibrary methods in different thread heap is not getting corrupted and sub-sequently JVM is not being crashed.
I run my application on a VMWare Linux guest, and it doesn't work well.
I write another simple counter to run on the same guest for testing.
(add counter every 0.5s)
Counter works fine while application stop,
but shortly hanged while appliction is running (marked time and numbers).
10:21:24.386 : 166
10:21:25.154 : 167
10:21:25.971 : 168
10:21:25.971 : 169 <--
10:21:26.957 : 170
10:21:26.957 : 171 <--
10:21:27.848 : 172
10:21:27.885 : 173
10:21:28.776 : 174
10:21:28.884 : 175
10:21:30.374 : 176
10:21:30.374 : 177 <--
10:21:30.379 : 178
10:21:31.264 : 179
10:21:31.380 : 180
10:21:32.155 : 181
10:21:32.933 : 182
10:21:32.933 : 183 <--
counter code shows below, but I don't think theres problem
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable(){
int i=0;
#Override
public void run() {
Calendar cal = Calendar.getInstance();
System.out.println(sdf.format(cal.getTime()) + " : " + i);
i++;
}
}, 500, 500, TimeUnit.MILLISECONDS);
Here's the top result while application is running
top - 11:02:49 up 20:49, 5 users, load average: 12.87, 14.66, 13.22
Tasks: 196 total, 5 running, 190 sleeping, 0 stopped, 1 zombie
%Cpu0 : 77.3 us, 20.5 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 2.3 si, 0.0 st
%Cpu1 : 82.4 us, 16.5 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 1.1 si, 0.0 st
KiB Mem : 16267652 total, 7639820 free, 7309136 used, 1318696 buff/cache
KiB Swap: 8257532 total, 8257532 free, 0 used. 8588648 avail Mem
It seems my application running out of resource and making JVM working improperly ?
Except for adding more resource to guest, is there any ways to reduce resource consuming?
Using jmap -histo to find mostly used object and check it ?
Hers's enviroment info
java version "1.8.0_181"
CentOS Linux release 7.5.1804 (Core)
VMware 6.0
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.
There are lots of good examples out there on how to read Microsoft Excel files into R with the XLConnect package, but I can't find any examples of how to read in an Excel file directly from a URL. The reproducible example below returns a "FileNotFoundException (Java)". But, I know the file exists because I can pull it up directly by pasting the URL into a browser.
fname <- "https://www.misoenergy.org/Library/Repository/Market%20Reports/20140610_sr_nd_is.xls"
sheet <- c("Sheet1")
data <- readWorksheetFromFile(fname, sheet, header=TRUE, startRow=11, startCol=2, endCol=13)
Although, the URL is prefixed with "https:" it is a public file that does not require a username or password.
I have tried to download the file first using download.file(fname, destfile="test.xls") and got a message that says it was downloaded but when I try to open it in Excel to check to see if it was successful i get a Excel popup box that says "..found unreadable content in 'test.xls'.
Below are the specifics of my system:
Computer: 64-bit Dell running
Operating System: Windows 7 Professional
R version: R-3.1.0
Any assistance would be greatly appreciated.
You can use RCurl to download the file:
library(RCurl)
library(XLConnect)
appURL <- "https://www.misoenergy.org/Library/Repository/Market%20Reports/20140610_sr_nd_is.xls"
f = CFILE("exfile.xls", mode="wb")
curlPerform(url = appURL, writedata = f#ref, ssl.verifypeer = FALSE)
close(f)
out <- readWorksheetFromFile(file = "exfile.xls", sheet = "Sheet1", header = TRUE
, startRow = 11, startCol = 2, endCol = 15, endRow = 35)
> head(out)
Col1 EEI Col3 IESO MHEB Col6 PJM SOCO SWPP TVA WAUE Col12 Other Total
1 Hour 1 272 NA 768 1671 NA 148 200 -52 198 280 NA 700 4185
2 Hour 2 272 NA 769 1743 NA 598 200 -29 190 267 NA 706 4716
3 Hour 3 272 NA 769 1752 NA 598 200 -28 194 267 NA 710 4734
4 Hour 4 272 NA 769 1740 NA 598 200 -26 189 266 NA 714 4722
5 Hour 5 272 NA 769 1753 NA 554 200 -27 189 270 NA 713 4693
6 Hour 6 602 NA 769 1682 NA 218 200 -32 223 286 NA 714 4662
Two things:
Try using a different package--I know the gdata package's read.xls function has support for URLs
Try loading in a publicly-available xls file to make sure it's not an issue with the particular website.
For instance, you can try:
library("gdata")
site <- "http://www.econ.yale.edu/~shiller/data/chapt26.xls"
data <- read.xls(site, header=FALSE, skip=8)
head(data)
XLConnect does not support importing directly from URLs. You have to use e.g. download.file first to download the file to your local machine:
require(XLConnect)
tmp = tempfile(fileext = ".xls")
download.file(url = "http://www.econ.yale.edu/~shiller/data/chapt26.xls", destfile = tmp)
readWorksheetFromFile(file = tmp, sheet = "Data", header = FALSE, startRow = 9, endRow = 151)
or with your originally proposed URL:
require(XLConnect)
tmp = tempfile(fileext = ".xls")
download.file(url = "https://www.misoenergy.org/Library/Repository/Market%20Reports/20140610_sr_nd_is.xls", destfile = tmp, method = "curl")
readWorksheetFromFile(file = tmp, sheet = "Sheet1", header = TRUE, startRow = 11, startCol = 2, endCol = 13)
library(relenium)
library(XML)
library(RCurl)
firefox=firefoxClass$new()
url="https://www.misoenergy.org/Library/Repository/Market%20Reports/20140610_sr_nd_is.xls"
url=sprintf(url)
firefox$get(url)
This will open a Firefox instance within R and ask you to download the file, which you could then open in the next line of code. I don't know of any R utilities that will open an excel spreadsheet from HTTPS.
You could then set a delay while you're saving the file and then read the sheet from your downloads folder:
Sys.sleep(10)
sheet <- c("Sheet1")
data <- readWorksheetFromFile(path, sheet, header=TRUE, startRow=11, startCol=2, endCol=13)
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.