Java平面文件解析器(jffp)LineFormatTest

时间:2022-10-29 13:42:26

I want to work with Java Flat File Parser (jffp) and am trying to run the TestCase (JUnit) "LineFormatTest" which is inside the src-file (and there after some clicking inside the file "test"). What I get is this error:

我想使用Java平面文件解析器(jffp)并尝试运行TestCase(JUnit)“LineFormatTest”,它位于src文件中(并在文件“test”中点击一些内容之后)。我得到的是这个错误:

org.sadun.text.ffp.FieldDefinitionException: Programming error: the fields field_1_1 (from position 0 to position5, length 5, type numeric) and field_1_1 (from position 0 to position5, length 5, type numeric) intersect

org.sadun.text.ffp.FieldDefinitionException:编程错误:字段field_1_1(从位置0到位置5,长度为5,类型为数字)和field_1_1(从位置0到位置5,长度为5,类型为数字)相交

Has anyone tried to run this TestCase and stumbled across this error as well?

有没有人试图运行这个TestCase并偶然发现了这个错误?

2 个解决方案

#1


3  

I have such trouble with jffp and JDK1.7. I investigated sources and found out that oracle correted a bit implementation of TreeMap which is used in TreeSet in JDK1.7, so jffp adds field definitions into the set but new implementation of map calls compare method for the first element with itself and comparator implemented in the jffp contains checking of positions of field element and if position the same it throws "programming exception". And if you take a look to exception description you will see that it compares the same field.

我在使用jffp和JDK1.7时遇到了麻烦。我调查了源代码,发现oracle对JDK1.7中TreeSet中使用的TreeMap的一些实现进行了修正,因此jffp将字段定义添加到集合中,但是地图调用的新实现比较了第一个元素与自身的比较方法和比较器实现的jffp包含对field元素位置的检查,如果位置相同则抛出“编程异常”。如果你看一下异常描述,你会发现它比较了同一个字段。

So, if you use jdk1.7 also then I don't see any light way solutions as rid of jffp or jdk1.7(back to 1.6).

所以,如果你也使用jdk1.7那么我没有看到任何轻松的解决方案,因为摆脱了jffp或jdk1.7(回到1.6)。

#2


2  

I just encountered the bug when using jdk1.7.0_55 and jffp. In Java 7 the comparator is invoked as soon as the first element is added to the TreeSet. So the first FieldInfo instance (o1) is compared against itself (o2); o1 and o2 obviously intersect.

我刚刚在使用jdk1.7.0_55和jffp时遇到了这个bug。在Java 7中,只要将第一个元素添加到TreeSet,就会调用比较器。所以将第一个FieldInfo实例(o1)与自身进行比较(o2); o1和o2明显相交。

Here is the fast and dirty solution I have tested successfully:

这是我成功测试的快速而肮脏的解决方案:

  1. Download jffp source code at sourceforge: http://sourceforge.net/projects/jffp/

    在sourceforge下载jffp源代码:http://sourceforge.net/projects/jffp/

  2. Take the LineFormat.java file and copy it in the org.sadun.text.ffp package in your project.

    获取LineFormat.java文件并将其复制到项目的org.sadun.text.ffp包中。

  3. Now modify the addFieldInfo private method and add a (f1 != f2) condition to the f1.intersects(f2) test to ensure a field is not tested against itself for intersection:

    现在修改addFieldInfo私有方法并在f1.intersects(f2)测试中添加一个(f1!= f2)条件,以确保不对交叉点自身测试字段:

     private void addFieldInfo(int physicalLine, FieldInfo info) {
           if (physicalLine > currentPhysicalLine)
              currentPhysicalLine = physicalLine;
           final Integer pl = new Integer(physicalLine);
           SortedSet l = (SortedSet) fieldsByLine.get(pl);
           if (l == null) {
              l = new TreeSet(new Comparator() {
                 public int compare(Object o1, Object o2) {
                    FieldInfo f1 = (FieldInfo) o1;
                    FieldInfo f2 = (FieldInfo) o2;
                    // fields must not intersect
                    if ((f1 != f2)
                          && f1.intersects(f2))
                       throw new FieldDefinitionException(
                             "Programming error: the fields "
                                   + f1
                                   + " and "
                                   + f2
                                   + " intersect");
                    return f1.start - f2.start;
    
                 }
              });
              fieldsByLine.put(pl, l);
           }
           l.add(info);
     }
    
  4. Compile and test.

    编译和测试。

I am going to reach the developer. Maybe he could build an official version to fix the bug.

我打算联系开发者。也许他可以建立一个正式版来修复这个bug。

#1


3  

I have such trouble with jffp and JDK1.7. I investigated sources and found out that oracle correted a bit implementation of TreeMap which is used in TreeSet in JDK1.7, so jffp adds field definitions into the set but new implementation of map calls compare method for the first element with itself and comparator implemented in the jffp contains checking of positions of field element and if position the same it throws "programming exception". And if you take a look to exception description you will see that it compares the same field.

我在使用jffp和JDK1.7时遇到了麻烦。我调查了源代码,发现oracle对JDK1.7中TreeSet中使用的TreeMap的一些实现进行了修正,因此jffp将字段定义添加到集合中,但是地图调用的新实现比较了第一个元素与自身的比较方法和比较器实现的jffp包含对field元素位置的检查,如果位置相同则抛出“编程异常”。如果你看一下异常描述,你会发现它比较了同一个字段。

So, if you use jdk1.7 also then I don't see any light way solutions as rid of jffp or jdk1.7(back to 1.6).

所以,如果你也使用jdk1.7那么我没有看到任何轻松的解决方案,因为摆脱了jffp或jdk1.7(回到1.6)。

#2


2  

I just encountered the bug when using jdk1.7.0_55 and jffp. In Java 7 the comparator is invoked as soon as the first element is added to the TreeSet. So the first FieldInfo instance (o1) is compared against itself (o2); o1 and o2 obviously intersect.

我刚刚在使用jdk1.7.0_55和jffp时遇到了这个bug。在Java 7中,只要将第一个元素添加到TreeSet,就会调用比较器。所以将第一个FieldInfo实例(o1)与自身进行比较(o2); o1和o2明显相交。

Here is the fast and dirty solution I have tested successfully:

这是我成功测试的快速而肮脏的解决方案:

  1. Download jffp source code at sourceforge: http://sourceforge.net/projects/jffp/

    在sourceforge下载jffp源代码:http://sourceforge.net/projects/jffp/

  2. Take the LineFormat.java file and copy it in the org.sadun.text.ffp package in your project.

    获取LineFormat.java文件并将其复制到项目的org.sadun.text.ffp包中。

  3. Now modify the addFieldInfo private method and add a (f1 != f2) condition to the f1.intersects(f2) test to ensure a field is not tested against itself for intersection:

    现在修改addFieldInfo私有方法并在f1.intersects(f2)测试中添加一个(f1!= f2)条件,以确保不对交叉点自身测试字段:

     private void addFieldInfo(int physicalLine, FieldInfo info) {
           if (physicalLine > currentPhysicalLine)
              currentPhysicalLine = physicalLine;
           final Integer pl = new Integer(physicalLine);
           SortedSet l = (SortedSet) fieldsByLine.get(pl);
           if (l == null) {
              l = new TreeSet(new Comparator() {
                 public int compare(Object o1, Object o2) {
                    FieldInfo f1 = (FieldInfo) o1;
                    FieldInfo f2 = (FieldInfo) o2;
                    // fields must not intersect
                    if ((f1 != f2)
                          && f1.intersects(f2))
                       throw new FieldDefinitionException(
                             "Programming error: the fields "
                                   + f1
                                   + " and "
                                   + f2
                                   + " intersect");
                    return f1.start - f2.start;
    
                 }
              });
              fieldsByLine.put(pl, l);
           }
           l.add(info);
     }
    
  4. Compile and test.

    编译和测试。

I am going to reach the developer. Maybe he could build an official version to fix the bug.

我打算联系开发者。也许他可以建立一个正式版来修复这个bug。