JNI - How to use the error reporting mechanism?

I've developed a C++ DLL which is loaded from a commercial Win32 application (not written by me) as a plug-in for external calculations. On its initialization the C++ DLL launches the Java VM via the JNI invocation interface. When the DLL functions are called by the application, they forward the calls to Java objects inside the Java VM, again via JNI invocation interface.
This works well, but I have encountered a weird error.
From Java I open a JFrame containing a JTextArea as small console for debug output messages. If I turn output to this debug console off (my printToConsole routine checks whether a boolean flag is set), the string concatenation operator may lead to a crash of the Java VM.
For example, if in one of the Java functions called from the
DLL via JNI invocation interface the following is the first statement,
it leads to a crash of the Java VM and the application that loaded the C++ proxy DLL.
String test=""+Math.random(); // String test not used later
Interestingly, if I comment this statement out, the Java code works fine WITHOUT any crash. I've already thought about potential races and synchronization issues in my code, but I don't see where this is the case. And the string concatenation error fails as well, if I insert sleep() statements in front of it and at other places in the code. However, if I turn on log messages printed to my JFrame debug console (containing a JTextArea), the String concatenation works without problems.
So maybe the JNI interface has a bug and affects the Java VM; I don't see where my JNI code is wrong.
One problem is that I do not get any stdout output, as the C++ proxy DLL is loaded by the Windows application, even if I start the Windows application from the DOS command line (under Windows).
Does anyone know how to use the error reporting mechanism?
http://java.sun.com/j2se/1.4.2/docs/guide/vm/error-handling.html
Is it possible that the JVM, when it crashes, writes debug information about the crash into a file instead of stdout/stderr?
My C++ proxy DLL was compiled in debug mode, but the commercial application (which loaded the DLL) is very likely not.
I do not know hot to find the reason why the String concatenation fails inside the Java function called from the C++ DLL via JNI.

Yes, I've initially thought about errors in the C++ code too. But the C++ code is actually very simple and short. It doesn't allocate anything on the C++ side. It allocates a couple of ByteBuffers inside the Java VM however via JNI invocation interface calls of env->NewDirectByteBuffer(). The native memory regions accessed via the ByteBuffers are allocated not by my own C++ code, but by the program that calls my DLL (the program is Metastock).
The interesting thing is that everything works fine if output to my debug console is enabled, which means that in the Java print routine getConsoleLoggingState() returns true and text is appended to the jTextArea.
static synchronized void print(String str)
{ MetaStockMonitor mMon=getInstance();
if ( mMon.getFileLoggingState() && mMon.logFileWriter!=null) {
mMon.logFileWriter.print(str);
mMon.logFileWriter.flush();
if ( mMon.getConsoleLoggingState() ) {
mMon.jTextArea1.append(str);
Only if output to the JTextArea is turned off (ie. getConsoleLoggingState()==false), the crash happens when the FIRST statement in the Java routine called via JNI invocation interface is a (useless) String concatenation operation, as described above.
String test=""+Math.random(); // String test not used later
Moreover, the crash happens BEFORE the allocated ByteBuffer objects are accessed in the Java code. But again, if console output is turned on, it works stable. If console output is turned off, it works when the (useless) String concatenation operation is removed in the Java routine called from C++.
I've already thought about potential races (regarding multiple threads), but this can be ruled out in my case. It almost appears as if the JVM can have problems when called by the invocation interface (I tested it with Java 1.4.2 b28).
All the calls between C++ and Java go ALWAYS in the direction from C++ code to Java. Unfortunately, there is no special JRE version with extensive logging capabilities to facilitate debugging. And the problem is not easily reproducible either.
JNIEnv* JNI_GetEnv()
JNIEnv *env;
cached_jvm->AttachCurrentThread((void**)&env,NULL);
fprintf(logfile,"env=%i\n",env);
fflush(logfile);
return env;
// function called by Metastock's MSX plug-in interface
BOOL __stdcall createIndEngine (const MSXDataRec *a_psDataRec,
const MSXDataInfoRecArgsArray *a_psDataInfoArgs,
const MSXNumericArgsArray *a_psNumericArgs,
const MSXStringArgsArray *a_psStringArgs,
const MSXCustomArgsArray *a_psCustomArgs,
MSXResultRec *a_psResultRec)
a_psResultRec->psResultArray->iFirstValid=0;
a_psResultRec->psResultArray->iLastValid=-1;
jthrowable ex;
jmethodID mid;
JNIEnv* env=JNI_GetEnv();
jobject chart=getChart(env, a_psDataRec);
if ( chart==NULL) {
return MSX_ERROR;
jobject getChart (JNIEnv* env, const MSXDataRec *a_psDataRec)
jthrowable ex;
jmethodID mid;
int closeFirstValid, closeLastValid;
closeFirstValid=a_psDataRec->sClose.iFirstValid;
closeLastValid=a_psDataRec->sClose.iLastValid;
long firstDate, firstTime;
if (closeFirstValid>=1 && closeFirstValid<=closeLastValid) {
firstDate = a_psDataRec->psDate[closeFirstValid].lDate;
firstTime = a_psDataRec->psDate[closeFirstValid].lTime;
} else {
firstDate=0;
firstTime=0;
jclass chartFactoryClass = env->FindClass("wschwendt/metastock/msx/ChartFactory");
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot find class ChartFactory\n");
printSBufViaJava(sbuf);
return NULL;
mid = env->GetStaticMethodID(chartFactoryClass, "getInstance", "()Lwschwendt/metastock/msx/ChartFactory;");
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot find method ID for ChartFactory.getInstance()\n");
printSBufViaJava(sbuf);
return NULL;
jobject chartFactory=env->CallStaticObjectMethod(chartFactoryClass, mid);
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Exception while calling ChartFactory.getInstance()");
printSBufViaJava(sbuf);
return NULL;
mid = env->GetMethodID(chartFactoryClass, "getChartID", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;IIIIIII)F");
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot find method ID for ChartFactory.getChartID()\n");
printSBufViaJava(sbuf);
return NULL;
jobject symbolBuf=env->NewDirectByteBuffer(a_psDataRec->pszSymbol, strlen(a_psDataRec->pszSymbol) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate symbolBuf\n");
printSBufViaJava(sbuf);
return NULL;
jobject securityNameBuf=env->NewDirectByteBuffer(a_psDataRec->pszSecurityName, strlen(a_psDataRec->pszSecurityName) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate securityNameBuf\n");
printSBufViaJava(sbuf);
return NULL;
jobject securityPathBuf=env->NewDirectByteBuffer(a_psDataRec->pszSecurityPath, strlen(a_psDataRec->pszSecurityPath) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate securityPathBuf\n");
printSBufViaJava(sbuf);
return NULL;
jobject securityOnlineSourceBuf=env->NewDirectByteBuffer(a_psDataRec->pszOnlineSource, strlen(a_psDataRec->pszOnlineSource) );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Cannot allocate onlineSourceBuf\n");
printSBufViaJava(sbuf);
return NULL;
// Java Function call leads to crash, if console output is turned off and
// the first statement in the Java routine is a (useless) string concatenation.
// Otherwise it works stable.
jfloat chartID=env->CallFloatMethod(chartFactory, mid, securityNameBuf, symbolBuf,
securityPathBuf, securityOnlineSourceBuf, (jint)(a_psDataRec->iPeriod),
(jint)(a_psDataRec->iInterval), (jint)(a_psDataRec->iStartTime),
(jint)(a_psDataRec->iEndTime), (jint)(a_psDataRec->iSymbolType),
(jint)firstDate, (jint)firstTime );
if (ex= env->ExceptionOccurred() ) {
env->ExceptionDescribe();
env->ExceptionClear();
sprintf(sbuf, "DLL: Exception while calling ChartFactory.getChartID()");
printSBufViaJava(sbuf);
return NULL;

Similar Messages

  • How to use the repository; uploading reports from DEV to PROD...

    Hello...
    I'm fairly new to CR-XIr2 (SP3) but have worked with Crystal Reports since v6.0.  I'm trying to figure out how to create a dynamic parameter list that someone can select an item from, which will get sent as an input parameter to the SQL Server 2005 stored proc that populates the report.  I'm also trying to figure out if there's an easy way to copy reports from a DEV environment into PROD.  We have BOE.
    Basically, I would like to find out resources online or in books on how to use the BOE repository for dynamic and/or cascading parameters (i.e. pulling a list of text values & their associated IDs from a lookup table that won't be used in the report), images (i.e. corporate logo), etc..  What complicates things for us is that IT is now requiring us to use a DEV environmentit was really easy when we had unlimited access in PROD!  We also need to put together a process where reports & other repository objects that are copied from DEV to PROD access the correct db, etc.  (Crystal Report in DEV accesses DEV db/repository/etc.when copied to PROD it accesses PROD db/repository/etc.)
    Anyway, I'm just looking for info on where to begin--whether it be a book, a BO/SAP knowledge base article, in-class training from a specific company, etc.  Thanks!

    Hey Markian,
    Can you let me know the process you have followed to migrate from Dev to Prod.
    We can migrate all the reports and objects and database fields through migrate wizard where you can import all the objects, reports and database fields and users to production enterprise.
    Just follow the above scenario and let us know if you are facing any error.
    Try  publish the reports using import wizard and run it in the crystal designer.
    Regards,
    Naveen.

  • How to use the HTML tags in the reports.

    hi.
    can any one tell me how to use the HTML tags in the reports.
    i m using the forms 10 g rel 2 and reports 10 g rel 2 and application server 10g rel 2.

    Set the Contains HTML Tags property of an object to Yes, then the tags in the object's text (if any) will be used to format the object.

  • How do i use the bug reporter in ios 8

    im trying to use the bug reporter for the beta ios 8 but i dont get to input anything. Maybe i dont understand how this works,so can someone please explain.either way i figure i should say somthing now.
    -the infinity blade 2 app does not load
    -my settings button doesnt load all the time,
    -most of the apps dont load the first time i open them,if i switch to another menu then back it will load.
    -just now i shut off my phone, plugged it into the charger. My phone then turned itself back on and had me reactivate it.
    -the "sample" button in the ibooks app doesnt seem to do anything either
    -most of the time scrolling down on anything rather large(e.g.songs,articles,facebook) there is alot of skipping or lagging effect
    -when on safari i turn my phone sidways and it totally messes up where things should go and it wont return i have to exit and close to fix
    anyways id just thought id put that out there

    You need to ask this question in the Developer's forum, which as a registered developer you have access to. If you're not a registered developer, then you have no business messing with iOS Beta software, & discussing such, even bug reporting, is PROHIBITED in this public forum.
    But, as a registered developer, you already knew that, correct?

  • How to use the admin user account in reports and dashboards?

    Hi Everyone,
    I want to use the admin user account in report and dashboard connections. But the Hyperion is automatically using the current user's credentials to fetch data.
    Hyperion 11.1.1.1
    Thanks
    Syantan

    This has been posted in the essbase forum > How to use the admin user account in reports and dashboards?
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • How to display the alv report blocks wise with out using the blocked alv

    Hi
    How to display the alv report with out using the blocked alv function module.
    Thanks
    Chinnu

    see this Standard Program
    RPR_ABAP_SOURCE_SCAN

  • How to use the SCOM 2012 Web Reporting page

    Hello all-
       We are on SCOM 2012 SP1.  I just have a general question about reporting.  I know there is a "Reporting" tab in the real, locally installed, SCOM Operations Console software.  That part I get.  I see that there
    are many pre-made reports the for me to run.  For example under Microsoft Server 2008 Operating System (Monitoring) folder there is a
    Performance History report.  When I double click on it, it takes me to the report window where I can click
    Add Object and add a server and then click
    Run.  
    This is pretty simple in concept.   BUT very few people at my company have the full Operations Console installed on their machine.  And as I'm sure you know, the SCOM Web Console does not have a Reporting Tab.  So they have to use the
    SCOM Reporting website to run such reports.  I found that you can get to this page at the url:
    http://<reporting server>/Reports                       
    This does bring up the Reporting console.  On the list I do see a Report.Windows.Server.2008.PerformanceHistory listed. So this surely seems to be the equivalent from my screenshot above.   However, it's not even close to user friendly like
    the Reporting area in the SCOM operations console software. There's multiple fields at the top. All of which are required, and almost none of which have dropbox or other ways to help you fill them in. I have no idea what to put into these boxes or the format
    to use.
    What am I missing here?  Is there a more user friendly interface anywhere?  In an ideal world, I'd really love to have a user interface where I can post the links to a few popular reports, like CPU and Disk Space for example.  Then ideally
    all the user would have to do is select their servers and the time frame and that's all.   Which really is what you do in the Operations Console software.   So isn't is it that easy in the web reporting tool?  Is there a guide or how-to
    section somewhere I'm missing?  Or just a more friendly looking way to get at this information?

    Well, my first screen shot above is squished, so you really can't see it.  But what I'm saying is that the same report in the SCOM software has the level of configuration I want on it.   It allows you to pick the date range and add objects
    to it, then you can click on Run.     However when I access the same report on the reporting console, it has all these extra fields.  None of which I know how to fill in properly.
    I would ultimately like my customers to be able to do exactly that in the web version.  Pick their server and their date range and run it.   There are not likely going to be too many reports like you're mentioning which I can completely configure
    before hand, so they just click on the link to have it run.  Most times I'd like my users to at least be able to select a server name.
    Any idea how I would simplify the web version of the report?  Or why they look so very different?

  • How to handle the errors using RSRV tcode

    Hi all,
           Could any one give tell me how to handle the errors,(if possible give me some example errors)and correct the errors using RSRV tcode.
    Thanks & Regards,
    Aswini.

    Hello Aswini,
    For further details on RSRV go through the link:
    http://help.sap.com/saphelp_nw04/helpdata/en/92/1d733b73a8f706e10000000a11402f/frameset.htm
    Hope it helps
    Cheers
    SRS

  • How to use the dll  created by c++ but not write a jni wrapper around

    how to use the dll created by c++ but not write a jni wrapper around through a java program. now I can't access that dll like this directly from java.

    Your question is unclear. (You haven't said what dll you are talking about.)
    But:
    If you are talking about an existing dll, then the only alternative to writing a wrapper is to use one of the wrapper generators floating around. Do a search on JACE.
    If you are talking about a dll you are writing, then run jah and get the interface to match java right away; then you won't have to write a wrapper.

  • How can I restore the 'Don't Ask Me Again' popup in the error reporter?

    I accidentally hit the option in the error reporter so that it sends out information without asking. I'd prefer to have the always ask option. How can I reset the preference?

    First check the following setting. In the Tools menu select Options. In the Options dialog go to the General panel and make sure the setting "When Firefox Starts" is not set to "Show my windows and tabs from last time", you can set it to either of the other 2 choices.
    Now reset the 3 preferences that relate to warning when closing Firefox.
    # Type '''about:config''' into the location bar and press enter
    # Accept the warning message that appears, you will be taken to a list of preferences
    # Find the following 3 preferences, right-click on them and choose '''Reset''' (if reset is not available they will already be at their default value)
    ## browser.tabs.warnOnClose
    ## browser.warnOnQuit
    ## browser.warnOnRestart

  • How to use use the web report service to be consumed by web development?

    Hi guys,
    How can I pass the report server web service to web developers so they can use reports dataset data?
    Can some one post me a clear example?
    Thank you

    Hi Swallow,
    Thank you, it's helpful but from my own perspective, I would like to know how to use the methods on the url itself.
    For instance, my webservice is in http://<servername>/ReportServer/ReportService2010.asmx
    Now I would like to understand how I can add methods on the url itself like this (don't mind the incorrect syntax thats what I'm trying to figure it out)
    http://srv-bisp-dev/ReportServer/ReportService2010.asmx?op=GetDataSetData=<DatasetName>
    In the end,I would like to press enter and show the dataset result on the browser in xml tags.
    I don't even know if this is possible so I'm sending clay to the wall.

  • How to customize the error messages in web analysis reports

    Does anyone know how to customize the error messages that web analysis shows ,
    I want to customize the below error message with a custom error message
    "Document does not exist or no authorization to open document.Error occurred while loading document"
    Does anyone know how to do this ?

    Rajesh,
    you may want to check these links
    How to the Change the Application Stopped Message
    How to Change the Dispatcher Running, No Server Connected Message
    http://help.sap.com/saphelp_nw70/helpdata/en/65/18fc3f9ec4e669e10000000a155106/frameset.htm
    Thanks
    Bala Duvvuri

  • What is the error report thing

    evertime i try to get on itunes, a box pops up and says itunes has encountered a problem and needs to close. We are sorry for the inconenience. and then it gives me the option to send the error report or not to send. i tried both and nothing happens. can someone please help me out.
    sony   Windows XP   laptop

    Error reporting is a Windows feature that allows you to send a message to Microsoft whenever a program becomes unresponsive, crashes, or in general doesn't work the way it's supposed to work. Supposedly Microsoft evaluates these reports and releases bug fixes as necessary for Windows customers.
    It doesn't have anything to do directly with iTunes and won't help fix the underlying problem you're experiencing. Others are also having difficulty launching iTunes--you can search these forums for your particular problem/error message (do you get an error reference number?) and then see if any of the suggested fixes work.
    On Edit: After you send the error report to Microsoft you'll get a box with a link in it that may give you some useful tips from Microsoft on how to fix the problem. Make sure you click on the hyperlink in the "error report received" box and see what Microsoft suggests.

  • Assistance with Printing to Zebra QL220 using the LabVIEW report VI

    I currently am trying to use the LabVIEW report VI to output a formatted set of strings to the above mentioned printer.
    The UMPC hardware that runs the developed application is bare bones XP box and doesn't' have MS office installed
    I use the LV new report set to a standard report and  successfully set orientation to portrait or Landscape, set margins and set report fonts and headers.. However  in sending the text strings to this label printer (labels are 45mm X 60mm) I find that that two issues arise.
    1. Printing out double labels. The pagination fails and prints a blank label after each print when text is output.  However if I disable all headers and body text (i.e blank label print). This pagination works fine.?
    2. The formatting of the information on the page reliably, I currently use inserted blank spaces, is there a better way?
    I thought, perhaps I should try using the ZLP programming language, but then not sure how to I send it to a USB printer? Has any one had any experience with this and these label printers ?  
    Thanks
    Greg Nicholls

    hi all
    i am C sharp programer
    and i have zebra QL 220 plus
    and roll type is 42X20mm
    and i have the zebra sdk
    and i create mobile application in C# smart device
    and i tring to connect to printer from my application by bluetooth
    in sdk i got this and use
    using System;
    using ZSDK_API.Comm;
    using System.Text;
    using System.Threading;
    // This example prints "This is a ZPL test." near the top of the label.
    private void SendZplOverBluetooth(String theBtMacAddress) {
    try {
    // Instantiate a connection for given Bluetooth(R) MAC Address.
    ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection(theBtMacAddress);
    // Open the connection - physical connection is established here.
    thePrinterConn.Open();
    // Defines the ZPL data to be sent.
    String zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
    // Send the data to the printer as a byte array.
    thePrinterConn.Write(Encoding.Default.GetBytes(zplData));
    // Make sure the data got to the printer before closing the connection
    Thread.Sleep(500);
    // Close the connection to release resources.
    thePrinterConn.Close();
    } catch (Exception e) {
    // Handle communications error here.
    Console.Write(e.StackTrace);
    // This example prints "This is a CPCL test." near the top of the label.
    private void SendCpclOverBluetooth(String theBtMacAddress) {
    try {
    // Instantiate a connection for given Bluetooth(R) MAC Address.
    ZebraPrinterConnection thePrinterConn = new BluetoothPrinterConnection(theBtMacAddress);
    // Open the connection - physical connection is established here.
    thePrinterConn.Open();
    // Defines the CPCL data to be sent.
    String cpclData = "! 0 200 200 210 1\r\n"
    + "TEXT 4 0 30 40 This is a CPCL test.\r\n"
    + "FORM\r\n"
    + "PRINT\r\n";
    // Send the data to the printer as a byte array.
    thePrinterConn.Write(Encoding.Default.GetBytes(cpclData));
    // Make sure the data got to the printer before closing the connection
    Thread.Sleep(500);
    // Close the connection to release resources.
    thePrinterConn.Close();
    } catch (Exception e) {
    // Handle communications error here.
    Console.Write(e.StackTrace);
     and once i use ZPL method it print 17 barcod always with 16 blank Patches (labels)
    and  when i use CPCL method it print 12 BarCode always with 11 blank Patches (labels)
    and i dont know why ?
    it must print 1 Patch (label)
    what i can do  and i dont think there is eny rong with my code
    all waht i want is how i can give Length and width and how much label print coz it is always print 17 or 12 what i can do ?

  • How to delete the error stack in process chain?

    Hi all,
    we just want to do the following:
    - we are loading in FULL daily to our datatarget (data is versionized by 0calday)
    - we want to use the error-stack in order to analyze wrong data
    --> but we now encounter the problem that, if data has once been added to the error stack and has not been handled yet, all data from the next daily load will be sorted out as records with this key do already exist in the error-stack. But that's exactly what we want to avoid.
    with other words: how can we delete the records in the error stack by a report by e.g. using this in a process chain?
    Thanks in advance,
    Best regards,
    bivision
    Edited by: bivision2009 on Jul 6, 2010 12:25 PM

    Dbl click that DTP.... From menu... Extras -> Setting for Error Stack
    Here U can see error stack table name /BIC/B0001234000.
    Using SE38, create simple program "Delete from /BIC/B0001234000"
    In the process chain, add process type "ABAP Program" to add above deletion statement.

Maybe you are looking for