java.lang.IllegalArgumentException: unrecognized flag [ ] 11

JIRA | Daniel Gottlieb | 3 years ago
  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
  3. 0

    java.lang.IllegalArgumentException: subscription flag

    GitHub | 6 months ago | zhivko
    java.lang.IllegalArgumentException: subscription flag
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How to set -XX:PermSize=64m in maven-compiler-plugin?

    Stack Overflow | 2 years ago | feder
    org.codehaus.plexus.compiler.CompilerException: invalid flag: -XX:MaxPermSize
  6. 0

    Pure NetBeans doesn't work

    Stack Overflow | 7 years ago | rauch
    java.lang.IllegalArgumentException: invalid flag: -g:

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    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