|
[ https://issues.apache.org/jira/browse/OFBIZ-10645?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16683456#comment-16683456 ] Mathieu Lirzin commented on OFBIZ-10645: ---------------------------------------- What I mean is that you can use [{{Optional<T>}}|https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html] type as a return value of the {{buildEntity}} method. The idea it to be explicit about the potential absence of value, and let the type system know. Consider this dummy example: {code:java} String producer() { if (...) { return null; } else { return "result"; } } void consumer() { String res = producer(); if (res != null) { System.out.print("success"); } } {code} In the above code the fact that {{null}} represent an empty value is implicit and the compiler has no way to check that the empty case is properly handled. Now let's see how we could rewrite the code using {{Optional<T>}}: {code:java} Optional<String> producer() { if (...) { return Optional.empty(); } else { return Optional.of("result"); } } void consumer() { producer().ifPresent(System.out::println); } {code} In the above code {{producer}} return value is explicit about the potential emptiness of its result, additionally the compiler helps you in ensuring that in {{consumer}} you are not calling a method on a {{null}} value. Of course this example is trivial enough that the additional type safety it brings is overkill, however in real Java code this is really helpful. Does it make sense? > Empty entity name should not be allowed in entity definition > ------------------------------------------------------------ > > Key: OFBIZ-10645 > URL: https://issues.apache.org/jira/browse/OFBIZ-10645 > Project: OFBiz > Issue Type: Bug > Components: framework > Affects Versions: Trunk, Release Branch 16.11, Release Branch 17.12 > Reporter: Ashish Kumar Pandey > Assignee: Aditya Sharma > Priority: Trivial > Attachments: EntityMaintError.png, OFBIZ-10645-alternate.patch, OFBIZ-10645.patch > > > Present system allows empty name in entity definition due to which there SQLException in console log and error on Entity Mantainence page. > {code:java} > 2018-11-10 14:43:45,522 |OFBiz-batch-3 |DatabaseUtil |I| Error getting primary key info from database with null tableName, will try other means: java.sql.SQLException: Table name can not be null > 2018-11-10 14:43:45,522 |OFBiz-batch-1 |DatabaseUtil |I| Error getting primary key info from database with null tableName, will try other means: java.sql.SQLException: Table name can not be null > 2018-11-10 14:43:45,522 |OFBiz-batch-2 |DatabaseUtil |I| Error getting primary key info from database with null tableName, will try other means: java.sql.SQLException: Table name can not be null > 2018-11-10 14:44:06,198 |OFBiz-batch-2 |DatabaseUtil |W| Entity [] has no table in the database > 2018-11-10 14:44:06,243 |pool-3-thread-1 |DatabaseUtil |E| SQL Exception while executing the following: > CREATE TABLE OFBIZ. (TEST_ID VARCHAR(20) NOT NULL, LAST_UPDATED_STAMP TIMESTAMP, LAST_UPDATED_TX_STAMP TIMESTAMP, CREATED_STAMP TIMESTAMP, CREATED_TX_STAMP TIMESTAMP, PRIMARY KEY (TEST_ID)) > Error was: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 21. > java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 21. > at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.EmbedStatement.executeLargeUpdate(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.commons.dbcp2.DelegatingStatement.executeUpdate(DelegatingStatement.java:234) ~[commons-dbcp2-2.1.1.jar:2.1.1] > at org.apache.commons.dbcp2.DelegatingStatement.executeUpdate(DelegatingStatement.java:234) ~[commons-dbcp2-2.1.1.jar:2.1.1] > at org.apache.ofbiz.entity.jdbc.DatabaseUtil.createTable(DatabaseUtil.java:1677) [ofbiz.jar:?] > at org.apache.ofbiz.entity.jdbc.DatabaseUtil$CreateTableCallable.call(DatabaseUtil.java:1516) [ofbiz.jar:?] > at org.apache.ofbiz.entity.jdbc.DatabaseUtil$CreateTableCallable.call(DatabaseUtil.java:1502) [ofbiz.jar:?] > at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_66] > at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_66] > at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_66] > at java.lang.Thread.run(Thread.java:745) [?:1.8.0_66] > Caused by: org.apache.derby.iapi.error.StandardException: Syntax error: Encountered "(" at line 1, column 21. > at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.iapi.error.StandardException.newException(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.sql.compile.ParserImpl.parseStatementOrSearchCondition(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source) ~[derby-10.14.1.0.jar:?] > at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source) ~[derby-10.14.1.0.jar:?] > ... 12 more > 2018-11-10 14:44:06,259 |pool-3-thread-1 |DatabaseUtil |E| Could not create table [OFBIZ.]: SQL Exception while executing the following: > CREATE TABLE OFBIZ. (TEST_ID VARCHAR(20) NOT NULL, LAST_UPDATED_STAMP TIMESTAMP, LAST_UPDATED_TX_STAMP TIMESTAMP, CREATED_STAMP TIMESTAMP, CREATED_TX_STAMP TIMESTAMP, PRIMARY KEY (TEST_ID)) > Error was: java.sql.SQLSyntaxErrorException: Syntax error: Encountered "(" at line 1, column 21.{code} > !EntityMaintError.png! -- This message was sent by Atlassian JIRA (v7.6.3#76005) |
| Free forum by Nabble | Edit this page |
