Fix entities named String so they either compile, or are flagged as illegal. - Mendix Forum

Fix entities named String so they either compile, or are flagged as illegal.

5

At present, it is possible to create an entity in your Domain Model called String. This is legal in Mendix, but it will cause problems when building your application. Mendix will create proxy class called String for this entity when building, however, this will cause Java compilation problems as it will clash with the standard java.lang.String class.

I think there are two solutions to this.

  1. Don’t allow entities with names that will clash with standard Java classes (such as “String”).
  2. Change the generated proxy classes to use full namespaces to avoid clashes.

 

asked
2 answers

There seems to be a warning available in Studio Pro (9.21) already:


Code: CW9503

Message: Using the name 'String' can cause issues during deployment and will be reserved in the future.

Element: Entity 'Test.String'

Document: Domain model

Module: Test

But as you cannot even compile the application after naming an entity String, might be better to use one of your solutions indeed!:
 

compile:
    [javac] Compiling 366 source files to \deployment\run\bin
    [javac] \javasource\test\proxies\Bestand.java:49: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Bestand.java:82: error: cannot find symbol
    [javac]         return com.mendix.core.Core.createXPathQuery(String.format("//%1$s%2$s", entityName, xpathConstraint))
    [javac]                                                            ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Entity.java:52: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Entity_2.java:50: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Entity_3.java:51: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Entity_3.java:87: error: cannot find symbol
    [javac]         return com.mendix.core.Core.createXPathQuery(String.format("//%1$s%2$s", entityName, xpathConstraint))
    [javac]                                                            ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Entity_4.java:50: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\Entity_4.java:86: error: cannot find symbol
    [javac]         return com.mendix.core.Core.createXPathQuery(String.format("//%1$s%2$s", entityName, xpathConstraint))
    [javac]                                                            ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\String.java:29: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\String.java:65: error: cannot find symbol
    [javac]         return com.mendix.core.Core.createXPathQuery(String.format("//%1$s%2$s", entityName, xpathConstraint))
    [javac]                                                            ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\textbox.java:50: error: cannot find symbol
    [javac]             throw new java.lang.IllegalArgumentException(String.format("The given object is not a %s", entityName));
    [javac]                                                                ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] \javasource\test\proxies\textbox.java:86: error: cannot find symbol
    [javac]         return com.mendix.core.Core.createXPathQuery(String.format("//%1$s%2$s", entityName, xpathConstraint))
    [javac]                                                            ^
    [javac]   symbol:   method format(java.lang.String,java.lang.String,java.lang.String)
    [javac]   location: class test.proxies.String
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] 12 errors

BUILD FAILED
\deployment\build_core.xml:30: Compile failed; see the compiler error output for details.
 

Created

Good idea!

Created