Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0037943Openbravo ERPA. Platformpublic2018-02-15 18:552018-03-14 19:15
caristu 
jarmendariz 
highminorhave not tried
closedfixed 
5
 
3.0PR18Q2 
caristu
Core
No
0037943: JDK 9: remove [deprecation] newInstance() in Class warnings
When building Openbravo with JDK 9, several "[deprecation] newInstance() in Class" warnings appears:

warning: [deprecation] newInstance() in Class has been deprecated

Besides, it seems that is not a recommended practice to make use of this method. So, these warnings should be fixed by retrieving the instance from a constructor object. See [1] and [2].

This is a safe change as Class.newInstance() is more limited than Constructor.newInstance(): the first one can only invoke the zero-argument constructor, while the second one may invoke any constructor. So, in order to fix this issue we have just to:

a) Replace calls to Class.newInstance() with Constructor.newInstance() without using any argument.
b) Catch the new exception types that are thrown by Constructor.newInstance(): InvocationTargetException and NoSuchMethodException. Both of these exception types are subclasses of ReflectiveOperationException.

[1] https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html [^]
[2] https://docs.oracle.com/javase/tutorial/reflect/member/ctorInstance.html [^]
1. Build Openbravo with Java 9
  -> Check warnings
Approved
related to feature request 0037083 closed alostale Openbravo ERP support JDK 9 
related to defect 0038000 closed jarmendariz Openbravo ERP API change for ExternalConnectionPool.getInstance(String) method due to [deprecation] newInstance() warning removal 
related to defect 0038095 closed jarmendariz Modules Handle new Exceptions thrown by ExternalConnectionPool.getInstance 
related to defect 0038115 closed jarmendariz Retail Modules JDK 9: Remove newInstance() deprecation warnings 
diff newInstanceRemovalFinal.diff (9,921) 2018-02-26 18:22
https://issues.openbravo.com/file_download.php?file_id=11604&type=bug
patch new-instance.patch (57,381) 2018-03-07 13:53
https://issues.openbravo.com/file_download.php?file_id=11620&type=bug
Issue History
2018-02-15 18:55caristuNew Issue
2018-02-15 18:55caristuAssigned To => platform
2018-02-15 18:55caristuModules => Core
2018-02-15 18:55caristuTriggers an Emergency Pack => No
2018-02-15 18:55caristuIssue generated from0037942
2018-02-15 18:55caristuRelationship addedrelated to 0037083
2018-02-15 19:04caristuDescription Updatedbug_revision_view_page.php?rev_id=16719#r16719
2018-02-16 09:19caristuSummaryJDK: remove [deprecation] newInstance() in Class warnings => JDK 9: remove [deprecation] newInstance() in Class warnings
2018-02-26 13:41caristuRelationship addedrelated to 0038000
2018-02-26 13:51caristuDescription Updatedbug_revision_view_page.php?rev_id=16769#r16769
2018-02-26 13:51caristuDescription Updatedbug_revision_view_page.php?rev_id=16770#r16770
2018-02-26 13:52caristuDescription Updatedbug_revision_view_page.php?rev_id=16771#r16771
2018-02-26 18:22caristuFile Added: newInstanceRemovalFinal.diff
2018-03-07 13:53jarmendarizFile Added: new-instance.patch
2018-03-09 14:34jarmendarizRelationship addedrelated to 0038095
2018-03-12 12:13jarmendarizAssigned Toplatform => jarmendariz
2018-03-12 12:13alostaleTag Attached: Approved
2018-03-12 12:40jarmendarizStatusnew => scheduled
2018-03-13 09:48hgbotCheckin
2018-03-13 09:48hgbotNote Added: 0103178
2018-03-13 09:48hgbotStatusscheduled => resolved
2018-03-13 09:48hgbotResolutionopen => fixed
2018-03-13 09:48hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/d526512e5e96cb6c5acf77a8451b82f233e4dd0c [^]
2018-03-13 09:50jarmendarizReview Assigned To => caristu
2018-03-13 13:20jarmendarizRelationship addedrelated to 0038115
2018-03-13 17:24hudsonbotCheckin
2018-03-13 17:24hudsonbotNote Added: 0103216
2018-03-14 19:15caristuNote Added: 0103251
2018-03-14 19:15caristuStatusresolved => closed
2018-03-14 19:15caristuFixed in Version => 3.0PR18Q2

Notes
(0103178)
hgbot   
2018-03-13 09:48   
Repository: erp/devel/pi
Changeset: d526512e5e96cb6c5acf77a8451b82f233e4dd0c
Author: Javier Armendáriz <javier.armendariz <at> openbravo.com>
Date: Fri Mar 09 14:18:48 2018 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/d526512e5e96cb6c5acf77a8451b82f233e4dd0c [^]

Fixed issue 37943: Removed newInstance() deprecation warnings.

Class.newInstance() is deprecated from JDK 9. It is replaced by Class.getDeclaredConstructor().newInstance(),
but it has the drawback that this call throws an instance of ReflectiveOperationException that must be taken
into account.

---
M modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/ad_actionbutton/ImportBankFile.java
M modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
M modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_MatchingTransaction.java
M modules/org.openbravo.client.application/src/org/openbravo/client/application/OBBindings.java
M modules/org.openbravo.client.application/src/org/openbravo/client/application/window/FormInitializationComponent.java
M modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinitionController.java
M modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceProperty.java
M src-core/src/org/openbravo/base/HttpBaseServlet.java
M src-core/src/org/openbravo/buildvalidation/BuildValidationHandler.java
M src-core/src/org/openbravo/database/ExternalConnectionPool.java
M src-core/src/org/openbravo/modulescript/ModuleScriptHandler.java
M src-wad/src/org/openbravo/wad/WadUtility.java
M src/org/openbravo/authentication/AuthenticationManager.java
M src/org/openbravo/base/model/ModelProvider.java
M src/org/openbravo/base/model/Reference.java
M src/org/openbravo/base/provider/OBProvider.java
M src/org/openbravo/costing/CostingServer.java
M src/org/openbravo/erpCommon/ad_forms/AcctServer.java
M src/org/openbravo/erpCommon/ad_forms/DocAmortization.java
M src/org/openbravo/erpCommon/ad_forms/DocBank.java
M src/org/openbravo/erpCommon/ad_forms/DocCash.java
M src/org/openbravo/erpCommon/ad_forms/DocCostAdjustment.java
M src/org/openbravo/erpCommon/ad_forms/DocDPManagement.java
M src/org/openbravo/erpCommon/ad_forms/DocDoubtfulDebt.java
M src/org/openbravo/erpCommon/ad_forms/DocFINBankStatement.java
M src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java
M src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
M src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java
M src/org/openbravo/erpCommon/ad_forms/DocGLJournal.java
M src/org/openbravo/erpCommon/ad_forms/DocInOut.java
M src/org/openbravo/erpCommon/ad_forms/DocInternalConsumption.java
M src/org/openbravo/erpCommon/ad_forms/DocInventory.java
M src/org/openbravo/erpCommon/ad_forms/DocInvoice.java
M src/org/openbravo/erpCommon/ad_forms/DocLCCost.java
M src/org/openbravo/erpCommon/ad_forms/DocLandedCost.java
M src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java
M src/org/openbravo/erpCommon/ad_forms/DocMovement.java
M src/org/openbravo/erpCommon/ad_forms/DocOrder.java
M src/org/openbravo/erpCommon/ad_forms/DocPayment.java
M src/org/openbravo/erpCommon/ad_forms/DocProduction.java
M src/org/openbravo/erpCommon/utility/GenericTreeServlet.java
M src/org/openbravo/erpCommon/utility/OBMessageUtils.java
M src/org/openbravo/scheduling/DefaultJob.java
---
(0103216)
hudsonbot   
2018-03-13 17:24   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/1d3ccc92fab6 [^]
Maturity status: Test
(0103251)
caristu   
2018-03-14 19:15   
Code reviewed + tested OK.