[x3d-public] bug in X3D Java SAI. comparing string arrays

yottzumm at gmail.com yottzumm at gmail.com
Wed Jan 4 14:15:58 PST 2017


The only reason the existing code works is because you are passing in an array list instead of a string array.  For example, I don’t think this code works like you expect:

        @Override
          public FontStyleObject setJustify(String[] newValue)
          {

                  // Check that newValue parameter has one of the allowed legal   values before assigning to scene graph
                  if (!(
                          Arrays.asList(newValue).equals(JUSTIFY_MIDDLE) ||
                          Arrays.asList(newValue).equals(JUSTIFY_MIDDLE_BEGIN) |  |
                          Arrays.asList(newValue).equals(JUSTIFY_MIDDLE_END) ||
                          Arrays.asList(newValue).equals(JUSTIFY_MIDDLE_FIRST) |  |
                          Arrays.asList(newValue).equals(JUSTIFY_MIDDLE_MIDDLE)   ||
                          Arrays.asList(newValue).equals(JUSTIFY_BEGIN) ||
                          Arrays.asList(newValue).equals(JUSTIFY_BEGIN_BEGIN) ||
                          Arrays.asList(newValue).equals(JUSTIFY_BEGIN_END) ||
                          Arrays.asList(newValue).equals(JUSTIFY_BEGIN_FIRST) ||                          Arrays.asList(newValue).equals(JUSTIFY_BEGIN_MIDDLE) |  |
                          Arrays.asList(newValue).equals(JUSTIFY_END) ||
                          Arrays.asList(newValue).equals(JUSTIFY_END_BEGIN) ||
                          Arrays.asList(newValue).equals(JUSTIFY_END_END) ||
                          Arrays.asList(newValue).equals(JUSTIFY_END_FIRST) ||
                          Arrays.asList(newValue).equals(JUSTIFY_END_MIDDLE) ||
                          Arrays.asList(newValue).equals(JUSTIFY_FIRST) ||
                          Arrays.asList(newValue).equals(JUSTIFY_FIRST_BEGIN) ||
                          Arrays.asList(newValue).equals(JUSTIFY_FIRST_END) ||
                          Arrays.asList(newValue).equals(JUSTIFY_FIRST_FIRST) ||                          Arrays.asList(newValue).equals(JUSTIFY_FIRST_MIDDLE)))   {
>>                        throw new org.web3d.x3d.sai.InvalidFieldValueException  ("FontStyle justify newValue=\"" +  Arrays.toString(newValue) + "\" has illega  l value, must use a valid enumeration string.");
                  }
                  if (newValue == null) return this; // newValueNullReturnThis
                  justify.clear(); // reset
                  for (int i = 0; i < newValue.length; i++)
                  {
                          justify.add(newValue[i]);
                  }

                  return this;
          }

Sent from Mail for Windows 10

From: yottzumm at gmail.com
Sent: Wednesday, January 4, 2017 5:05 PM
To: Don Brutzman; Roy Walmsley; x3d-public at web3d.org
Subject: RE: bug in X3D Java SAI. comparing string arrays

Changing this code is useful, because the Java SAI may be used from another language, say Python, from which converting from DOM to Python, the constants are not immediately available (but perhaps in the Object Model??).  We should allow for programmers to NOT use the constants, I think, in an understandable way, perhaps by providing our own equals method or by converting both Arrays to strings and then comparing the strings.

John

Sent from Mail for Windows 10

From: yottzumm at gmail.com
Sent: Tuesday, January 3, 2017 11:01 PM
To: Don Brutzman; Roy Walmsley; x3d-public at web3d.org
Subject: bug in X3D Java SAI. comparing string arrays

The following code shows the problem with comparing string arrays.  The equals returns false, so the exception is thrown.
Please revamp this code, then apply to stylesheet code to create better SAI.

John

package org;

import java.util.*;

public class X3DObject {
        public static final ArrayList<String> JUSTIFY_MIDDLE_MIDDLE = new ArrayList<>(Arrays.asList("\"MIDDLE\",\"MIDDLE\""));
        public X3DObject() {
        }
        public void setStringArray(String [] array) throws Exception {
               if (!(Arrays.asList(array).equals(JUSTIFY_MIDDLE_MIDDLE))) {
                       throw new Exception("Illegal "+ Arrays.toString(array));
               }
        }
        public static void main(String [] args) throws Exception {
               new X3DObject().setStringArray(new String[] {"MIDDLE", "MIDDLE"});
        }
}



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170104/3524540f/attachment-0001.html>


More information about the x3d-public mailing list