[x3d-public] Java SOCKS! jsail/Navigation/OrthoViewpoint.java in X3DJSAIL

John Carlson yottzumm at gmail.com
Tue Jul 29 21:55:41 PDT 2025


Apparently, the  FIELDOFVIEW_DEFAULT_VALUE should be final (immutable).  I
think the story is, you can modify elements of an ArrayList<Float>, but you
can't modify the variable.

The magenta?  Looks wrong.  A final variable got overwritten.
##########################################
((((getFieldOfView().length > 0) &&
!getFieldOfViewList().equals(FIELDOFVIEW_DEFAULT_VALUE)) ||
!ConfigurationProperties.getStripDefaultAttributes()) /* ArrayList .x3d
compare */ && !hasUSE())=false
getFieldOfView().length > 0=true
!getFieldOfViewList().equals(FIELDOFVIEW_DEFAULT_VALUE)=false
!ConfigurationProperties.getStripDefaultAttributes()=false
!hasUSE()=true
getFieldOfViewList()=[0.0, 0.0, 20.0, 20.0]
FIELDOFVIEW_DEFAULT_VALUE=[0.0, 0.0, 20.0, 20.0]
##########################################

Later, the magenta is correct.  Why?

##########################################
((((getFieldOfView().length > 0) &&
!getFieldOfViewList().equals(FIELDOFVIEW_DEFAULT_VALUE)) ||
!ConfigurationProperties.getStripDefaultAttributes()) /* ArrayList .x3d
compare */ && !hasUSE())=false
getFieldOfView().length > 0=true
!getFieldOfViewList().equals(FIELDOFVIEW_DEFAULT_VALUE)=false
!ConfigurationProperties.getStripDefaultAttributes()=false
!hasUSE()=true
getFieldOfViewList()=[-1.0, -1.0, 1.0, 1.0]
FIELDOFVIEW_DEFAULT_VALUE=[-1.0, -1.0, 1.0, 1.0]
##########################################

Here's the definition of the variable:

/** MFFloat field named <i>fieldOfView</i> has default value
<i>{-1f,-1f,1f,1f}</i> (Java syntax) or <i>-1 -1 1 1</i> (XML syntax). */
public static final ArrayList<Float> FIELDOFVIEW_DEFAULT_VALUE = new
ArrayList<>(Arrays.asList(-1f,-1f,1f,1f));

See example code to test (it gets even worse, even arrays themselves are
mutable.

import java.util.ArrayList;
import java.util.Arrays;

public class OArray {
        public static final ArrayList<Float> FIELDOFVIEW_DEFAULT_VALUE =
new ArrayList<>(Arrays.asList(-1f,-1f,1f,1f));
        public static final float[] ARRAY_FIELDOFVIEW_DEFAULT_VALUE = new
float [] {-1f,-1f,1f,1f};
        public static void main(String[] args) {
                System.out.println(FIELDOFVIEW_DEFAULT_VALUE);
                FIELDOFVIEW_DEFAULT_VALUE.set(0, 0f);
                FIELDOFVIEW_DEFAULT_VALUE.set(1, 0f);
                FIELDOFVIEW_DEFAULT_VALUE.set(2, 20f);
                FIELDOFVIEW_DEFAULT_VALUE.set(3, 20f);
                System.out.println(FIELDOFVIEW_DEFAULT_VALUE);
                System.out.print(
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[0]+" "+
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[1]+" "+
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[2]+" "+
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[3]);
                System.out.println("");
                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[0] = 0f;
                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[1] = 0f;
                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[2] = 20f;
                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[3] = 20f;
                System.out.print(
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[0]+" "+
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[1]+" "+
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[2]+" "+
                                ARRAY_FIELDOFVIEW_DEFAULT_VALUE[3]);
                System.out.println("");
        }
}
$ java net/coderextreme/OArray
[-1.0, -1.0, 1.0, 1.0]
[0.0, 0.0, 20.0, 20.0]
-1.0 -1.0 1.0 1.0
0.0 0.0 20.0 20.0

So, yeah, Java socks!  The only thing that isn't final/mutable is variables.

Don't you love the C foundation Java is based on?

Anyone for Haskell?

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20250729/70a5bdd6/attachment.html>


More information about the x3d-public mailing list