Question about detect if RMTES_STRING failed to encode

Carfield Yim
Carfield Yim Newcomer
edited April 11 in RFA

HI, for data type "OMMTypes.RMTES_STRING", I use below code to get the string to display it:

OMMDataBuffer buffer = (OMMDataBuffer)entryData

String dataDisplay = new String(buffer.getBytes, new RmtesCharsetProvider().charsetForName("RMTES"))

Most of the time it work but I can also get

java.nio.charset.CoderMalfunctionError: java.lang.IndexOutOfBoundsException

at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:587) ~[?:?]

at java.lang.String.decodeWithDecoder(String.java:1210) ~[?:?]

at java.lang.String.<init>(String.java:665) ~[?:?]

at java.lang.String.<init>(String.java:1387) ~[?:?]

Caused by: java.lang.IndexOutOfBoundsException

at java.nio.Buffer.checkIndex(Buffer.java:743) ~[?:?]

at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:169) ~[?:?]

at com.reuters.rmtes.RmtesCharsetDecoder.parseLangCode(Unknown Source) ~[feed-assembly-2.6.13.jar:2.6.13]

at com.reuters.rmtes.RmtesCharsetDecoder.parseEscSeq(Unknown Source) ~[feed-assembly-2.6.13.jar:2.6.13]

at com.reuters.rmtes.RmtesCharsetDecoder.decodeLoop(Unknown Source) ~[feed-assembly-2.6.13.jar:2.6.13]

at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:585) ~[?:?]

Just wonder how can I prevent that Exception with some kind of detection?

Tagged:

Answers

  • Hello @Carfield Yim

    Can you give me more detail about the issue?

    • I am assuming you are using the RFA Java API, what is the version of the RFA Java API that encounters the problem?
    • What is the RIC that encounter the issue?
    • What kind of data that an application tries to decode? Is it Market Price or News (MRN) data?
    • Can you replicate the issue with the RFA Java News Viewer application (rfaj8.2.5.L2.all.rrg package\Examples\com\reuters\rfa\example\omm\idn\newsviewer)
    • Can you try the RFA Java version 8.2.5.L2?
    • Is it data from exchange or your own publication?
  • Thanks a lot

    1. We are using 8.2.3.L1.all version
    2. We are using TREP with another data provider call ACTIV, and one symbol we got this problem was "TXG."
    3. It is market price
    4. Would you remind me the download page? Look like that is not in public maven repository, btw, look like my version is already new enough?
  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Carfield Yim

    Can you print the raw bytes hex data when the exception occurred?

    image.png

    We would like to check the data in the buffer.

  • Thanks a lot, how do you want the data to print out? If I just do "log.info (buffer.getBytes)" the I believe the output is like "[b@182decdb" , is that what you want?

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    That string is also useful but I would like to see the raw data.

    You can try the one mentioned on the StackOverflow.

  • HI, sure I see the value "44511B" most of the time, and few "51201B"

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    Do you mean the hex values are "0x44 0x51 0x1B" and "0x51 0x20 0x1B"?

    Did the library fail to decode these values?

  • Thanks, I believe it is, I copy below method to encode the byte

    private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
    public static String bytesToHex(byte[] bytes) {
    char[] hexChars = new char[bytes.length * 2];
    for (int j = 0; j < bytes.length; j++) {
    int v = bytes[j] & 0xFF;
    hexChars[j * 2] = HEX_ARRAY[v >>> 4];
    hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
    }
    return new String(hexChars);
    }

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Carfield Yim

    I tested with the following code.

    	public static void main(String[] args) {
    // TODO Auto-generated method stub
    byte[] bytes1 = HexFormat.of().parseHex("44511B");
    byte[] bytes2 = HexFormat.of().parseHex("51201B");

    String dataDisplay = new String(bytes2, new RmtesCharsetProvider().charsetForName("RMTES"));


    }

    I also got the exception.

    Exception in thread "main" java.nio.charset.CoderMalfunctionError: java.lang.IndexOutOfBoundsException
    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:588)
    at java.base/java.lang.String.decodeWithDecoder(String.java:1247)
    at java.base/java.lang.String.<init>(String.java:681)
    at java.base/java.lang.String.<init>(String.java:1425)
    at main.main(main.java:12)
    Caused by: java.lang.IndexOutOfBoundsException
    at java.base/java.nio.Buffer$1.apply(Buffer.java:757)
    at java.base/java.nio.Buffer$1.apply(Buffer.java:754)
    at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
    at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
    at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
    at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:106)
    at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:302)
    at java.base/java.nio.Buffer.checkIndex(Buffer.java:768)
    at java.base/java.nio.HeapByteBuffer.get(HeapByteBuffer.java:176)
    at com.reuters.rmtes.RmtesCharsetDecoder.parseLangCode(Unknown Source)
    at com.reuters.rmtes.RmtesCharsetDecoder.parseEscSeq(Unknown Source)
    at com.reuters.rmtes.RmtesCharsetDecoder.decodeLoop(Unknown Source)
    at java.base/java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:586)
    ... 4 more

    You may need to contact the ACTIV data provider to verify those values.

  • I see, yes understand it probably the data provider issue but at API level it would be great to have API like "isparsable()" for API user to detect if it is parsable or not

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @Carfield Yim

    It could be an enhancement request that should be submitted to the API support team via Contact Premium Support.

    However, the application can catch the error.

    		try {
    String dataDisplay = new String(bytes2, new RmtesCharsetProvider().charsetForName("RMTES"));
    }catch (java.nio.charset.CoderMalfunctionError ex) {
    System.out.println("Exception:");
    System.out.println(ex.getMessage());
    }
  • yeah, that is what I am doing now, I was just think there is a way to detect this rather than try-catch, it ok, sound like we don't have that feature, I guess let me stick with what I am doing now