java.lang.IllegalArgumentException: unrecognized flag [ ] 11

JIRA | Daniel Gottlieb | 3 years ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    Code to reproduce: {code} import java.util.*; import java.util.regex.*; import com.mongodb.*; import org.bson.*; public class BadPattern { public static void main(String[] jargs) throws Exception { Mongo mongo = new MongoClient(); DBCollection coll = mongo.getDB("test").getCollection("patterns"); coll.drop(); List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("pattern_string_1")); patterns.add(Pattern.compile("pattern_string_2")); coll.insert(new BasicDBObject("patterns", patterns)); coll.setDBDecoderFactory(LazyDBDecoder.FACTORY); LazyDBObject obj = (LazyDBObject)coll.findOne(); System.out.println(obj.get("patterns")); } } {code} Output: {noformat} Exception in thread "main" java.lang.IllegalArgumentException: unrecognized flag [ ] 11 at org.bson.BSON.regexFlags(BSON.java:94) at org.bson.LazyBSONObject.getElementValue(LazyBSONObject.java:597) at org.bson.LazyBSONList$LazyBSONListIterator.next(LazyBSONList.java:91) at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:274) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSON.serialize(JSON.java:56) at com.mongodb.util.JSON.serialize(JSON.java:41) at org.bson.LazyDBList.toString(LazyDBList.java:29) at java.lang.String.valueOf(String.java:2854) at java.io.PrintStream.println(PrintStream.java:821) {noformat} Note I chose to create a list of two patterns. The problem is more visible as an IllegalArgumentException gets bubbled up. In the case of a single pattern followed by the end of the bson document results in an empty string being read in, thus no visible error. (I believe the null terminator being found is the end of the bson document). In LazyBSONObject, the code to parse a pattern in `getElementValue` is: {code} case BSON.REGEX: int patternCStringSize = sizeCString( record.valueOffset ); String pattern = _input.getCString( record.valueOffset ); String flags = _input.getCString( record.valueOffset + patternCStringSize + 1 ); return Pattern.compile( pattern, BSON.regexFlags( flags ) ); {code} I _believe_ the `+ 1` part in parsing the flags should be removed.

    JIRA | 3 years ago | Daniel Gottlieb
    java.lang.IllegalArgumentException: unrecognized flag [ ] 11
  2. 0

    Code to reproduce: {code} import java.util.*; import java.util.regex.*; import com.mongodb.*; import org.bson.*; public class BadPattern { public static void main(String[] jargs) throws Exception { Mongo mongo = new MongoClient(); DBCollection coll = mongo.getDB("test").getCollection("patterns"); coll.drop(); List<Pattern> patterns = new ArrayList<Pattern>(); patterns.add(Pattern.compile("pattern_string_1")); patterns.add(Pattern.compile("pattern_string_2")); coll.insert(new BasicDBObject("patterns", patterns)); coll.setDBDecoderFactory(LazyDBDecoder.FACTORY); LazyDBObject obj = (LazyDBObject)coll.findOne(); System.out.println(obj.get("patterns")); } } {code} Output: {noformat} Exception in thread "main" java.lang.IllegalArgumentException: unrecognized flag [ ] 11 at org.bson.BSON.regexFlags(BSON.java:94) at org.bson.LazyBSONObject.getElementValue(LazyBSONObject.java:597) at org.bson.LazyBSONList$LazyBSONListIterator.next(LazyBSONList.java:91) at com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:274) at com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79) at com.mongodb.util.JSON.serialize(JSON.java:56) at com.mongodb.util.JSON.serialize(JSON.java:41) at org.bson.LazyDBList.toString(LazyDBList.java:29) at java.lang.String.valueOf(String.java:2854) at java.io.PrintStream.println(PrintStream.java:821) {noformat} Note I chose to create a list of two patterns. The problem is more visible as an IllegalArgumentException gets bubbled up. In the case of a single pattern followed by the end of the bson document results in an empty string being read in, thus no visible error. (I believe the null terminator being found is the end of the bson document). In LazyBSONObject, the code to parse a pattern in `getElementValue` is: {code} case BSON.REGEX: int patternCStringSize = sizeCString( record.valueOffset ); String pattern = _input.getCString( record.valueOffset ); String flags = _input.getCString( record.valueOffset + patternCStringSize + 1 ); return Pattern.compile( pattern, BSON.regexFlags( flags ) ); {code} I _believe_ the `+ 1` part in parsing the flags should be removed.

    JIRA | 3 years ago | Daniel Gottlieb
    java.lang.IllegalArgumentException: unrecognized flag [ ] 11

    Root Cause Analysis

    1. java.lang.IllegalArgumentException

      unrecognized flag [ ] 11

      at org.bson.BSON.regexFlags()
    2. MongoDB Java Driver
      LazyDBList.toString
      1. org.bson.BSON.regexFlags(BSON.java:94)
      2. org.bson.LazyBSONObject.getElementValue(LazyBSONObject.java:597)
      3. org.bson.LazyBSONList$LazyBSONListIterator.next(LazyBSONList.java:91)
      4. com.mongodb.util.JSONSerializers$IterableSerializer.serialize(JSONSerializers.java:274)
      5. com.mongodb.util.ClassMapBasedObjectSerializer.serialize(ClassMapBasedObjectSerializer.java:79)
      6. com.mongodb.util.JSON.serialize(JSON.java:56)
      7. com.mongodb.util.JSON.serialize(JSON.java:41)
      8. org.bson.LazyDBList.toString(LazyDBList.java:29)
      8 frames
    3. Java RT
      PrintStream.println
      1. java.lang.String.valueOf(String.java:2854)
      2. java.io.PrintStream.println(PrintStream.java:821)
      2 frames