Opened 8 years ago

Last modified 5 years ago

#4020 new defect

"JSON object expected ',' or '}'" error on FMU load

Reported by: anatoly.trosinenko@… Owned by: Adeel Asghar
Priority: normal Milestone: Future
Component: FMI Version:
Keywords: Cc:

Description

I try to load FMU generated by OpenModelica using JavaFMI library on Ubuntu 16.04 64 bit.
When loading with locale set to ru_RU.UTF-8 I get the following error:

JSON object expected ',' or '}', got: "lineEnd":2,"colStar

When I specify LANG=C it works well.

HOW TO REPRODUCE:

1) Compile the following model using OpenModelica 1.9.6:

model Trivial
  Real x;
equation
  x = time;
end Trivial;

2) Load it using the following Java code (uses JavaFMI 2.16.10 library) with LANG=ru_RU.UTF-8:

import org.javafmi.wrapper.generic.Simulation;

public class Test {
    public static void main(String args[]) {
        Simulation sim = new Simulation("/tmp/Trivial.fmu");
        sim.init(0.0, 1.0);
        sim.terminate();
    }
}

3) Repeat step 2 with LANG=C

EXPECTED BEHAVIOR:

Nothing is printed to terminal, program finishes correctly on both steps 2 and 3.

REAL BEHAVIOR:

On step 2, error message JSON object expected ',' or '}', got: "lineEnd":2,"colStar is printed to terminal and program terminates with SIGABRT.
On step 3 it works as expected.

DEBUGGING:

It seems that the problem is with the function skipValue() from file simulation_info_json.c that can be found inside an FMU in include/simulation directory.
It has the following code:

    char *endptr = NULL;
    strtod(str,&endptr);
    if (str == endptr) {
      fprintf(stderr, "Not a number, got %.20s\n", str);
       abort();
    }
    return endptr;

When using Russian locale, decimal delimiter is not point but comma, so when strtod is used to skip an integer in the middle of JSON object, it skips field delimiter too, that confuses skipObjectRest().

Change History (4)

comment:1 by anonymous, 8 years ago

You may have a look at the C locale specific string to number conversions, i.e. strtod_l from https://github.com/tbeu/ExternData/blob/master/ExternData/Resources/C-Sources/ED_locale.h.

comment:2 by Martin Sjölund, 8 years ago

I would be more interested in locale-independent fprintf working on all platforms.

We set locale to C explicitly to handle numbers correctly in OMC, but not in simulations. For this, you should not set a locale or set the comma delimiter to .. Java, sadly, does not support not setting the system locale on startup :(

comment:3 by marcus.l, 7 years ago

I have the same problem when using an FMU and pyfmi (Python). I'm using Swedish language. The problem doesn't show up directly when an load_fmu is called (pyfmi.load_fmu), but something in the locale backend must be triggered before. An example of doing this is to create an Qt4 app first

from PyQt4 import QtGui
a = QtGui.QApplication([])

After those lines the pyfmi.load_fmu call will cause a crash.

comment:4 by Martin Sjölund, 5 years ago

https://github.com/OpenModelica/OpenModelica/pull/871 should resolve the problem with FMUs not being able to read data correctly. Any printed data might still be wrong though (especially if external C functions are used).

Note: See TracTickets for help on using tickets.