Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0028119Openbravo ERPA. Platformpublic2014-11-07 09:512014-12-30 23:24
alostale 
AugustoMauch 
normalminorunable to reproduce
closedfixed 
5
 
3.0PR15Q1 
alostale
Core
No
0028119: potential NPE in DataSourceServiceProvider
There is a compilation warning in DataSourceServiceProvider:

Null pointer access: The variable ds can only be null at this location

problematic code is around line 84:

            if (ApplicationConstants.DATASOURCEBASEDTABLE.equals(table.getDataOriginType())) {
              dataSource = table.getObserdsDatasource();
              ds.setEntity(ModelProvider.getInstance().getEntityByTableId(table.getId()));
            }

This code was added by changest

changeset: 20346:faaff1ca4c4a
user: Augusto Mauch <augusto.mauch@openbravo.com>
date: Mon May 06 09:42:42 2013 +0200
summary: [DS Based Tables] Set the entity of the datasource

diff -r 8113618afb03 -r faaff1ca4c4a modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java Mon May 06 09:41:54 2013 +0200
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java Mon May 06 09:42:42 2013 +0200
@@ -81,6 +81,7 @@
             Table table = (Table) qTable.list().get(0);
             if (ApplicationConstants.DATASOURCEBASEDTABLE.equals(table.getDataOriginType())) {
               dataSource = table.getObserdsDatasource();
+ ds.setEntity(ModelProvider.getInstance().getEntityByTableId(table.getId()));
             }
           }
           if (dataSource == null) {
-
Check the flow, if it make sense fix it, if not remove
No tags attached.
related to feature request 00259963.0PR14Q3 closed AugustoMauch HQL based tables 
related to defect 00281173.0PR15Q1 closed alostale MultipleDeleteActionHandler throws an exception when removing several rows of a datasource based window 
Issue History
2014-11-07 09:51alostaleNew Issue
2014-11-07 09:51alostaleAssigned To => AugustoMauch
2014-11-07 09:51alostaleModules => Core
2014-11-07 09:51alostaleTriggers an Emergency Pack => No
2014-11-07 09:52alostaleDescription Updatedbug_revision_view_page.php?rev_id=6983#r6983
2014-11-07 09:55alostaleRelationship addedrelated to 0025996
2014-11-07 10:02alostaleRelationship addedrelated to 0028117
2014-11-17 18:07AugustoMauchIssue Monitored: alostale
2014-11-17 18:07AugustoMauchReview Assigned To => alostale
2014-11-17 18:08hgbotCheckin
2014-11-17 18:08hgbotNote Added: 0071722
2014-11-17 18:08hgbotCheckin
2014-11-17 18:08hgbotNote Added: 0071723
2014-11-17 18:08hgbotCheckin
2014-11-17 18:08hgbotNote Added: 0071724
2014-11-17 18:09hgbotCheckin
2014-11-17 18:09hgbotNote Added: 0071725
2014-11-17 18:09hgbotStatusnew => resolved
2014-11-17 18:09hgbotResolutionopen => fixed
2014-11-17 18:09hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/c77d6ec09d26a627f700bcd140454ad26052e7ca [^]
2014-11-17 18:09hgbotCheckin
2014-11-17 18:09hgbotNote Added: 0071726
2014-11-17 18:17AugustoMauchNote Added: 0071727
2014-11-17 18:18AugustoMauchNote Added: 0071728
2014-11-24 13:44alostaleNote Added: 0071937
2014-11-24 13:44alostaleStatusresolved => closed
2014-11-24 13:44alostaleFixed in Version => 3.0PR15Q1
2014-12-30 23:24hudsonbotCheckin
2014-12-30 23:24hudsonbotNote Added: 0073063
2014-12-30 23:24hudsonbotCheckin
2014-12-30 23:24hudsonbotNote Added: 0073064
2014-12-30 23:24hudsonbotCheckin
2014-12-30 23:24hudsonbotNote Added: 0073065
2014-12-30 23:24hudsonbotCheckin
2014-12-30 23:24hudsonbotNote Added: 0073066
2014-12-30 23:24hudsonbotCheckin
2014-12-30 23:24hudsonbotNote Added: 0073067

Notes
(0071722)
hgbot   
2014-11-17 18:08   
Repository: erp/devel/pi
Changeset: 2403611658277729f62f7fb351b2e0cf0cdba231
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Fri Nov 07 13:17:56 2014 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/2403611658277729f62f7fb351b2e0cf0cdba231 [^]

Related with issue 28119: DataSourceServiceProvider.getDataSource refactor #1

The DataSourceServiceProvider.getDataSource method is going to be refactored before fixing 28119, because its logic is very messy.

In this first part of the refactor the obtention of the DataSource and the obtention of the DataSourceService is going the be separated. The first part of the method now is in charge os retrieving the DataSource, and the second part obtains the DataSourceService associated with the DataSource.

---
M modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
---
(0071723)
hgbot   
2014-11-17 18:08   
Repository: erp/devel/pi
Changeset: d36de12150b1e1da1594f6fc5f8c8b4337492e7c
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Fri Nov 07 14:00:05 2014 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/d36de12150b1e1da1594f6fc5f8c8b4337492e7c [^]

Related with issue 28119: Refactor #2 and part of actual fix

Two methods have been extracted: getRealDataSource and getDataSourceServiceFromDataSource. In the previous changeset the retrieval of the DataSource and DataSource service was separated, now each code is in its respective method. I would have liked to name the first method getDataSource, but that name was already taken by the public method that returns a DataSourceServe.

This changeset also contains the first part of the fix. The original problem was that the entity of the DataSourceService was being set before the DataSourceService was initialized. This used to be done in the part that retrieved the DataSource, now it has been removed. The entity will be set to the DataSourceService in the next changeset.

---
M modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
---
(0071724)
hgbot   
2014-11-17 18:08   
Repository: erp/devel/pi
Changeset: ac61bb2afe11c922862986a4ae472f19a60a2db0
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Fri Nov 07 15:05:43 2014 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/ac61bb2afe11c922862986a4ae472f19a60a2db0 [^]

Related with issue 28119: Do not fail is trying to retrieve a null entity

The ModelProvider.getEntity method, which is used to retrieve an entity based on its table name, used to fail if an entity with the provided table name did not exist. This was not done when retrieving an entity given its table id or its table table_name.

Now it is possible to call to the getEntity method with an invalid table name without failing if the entity does not exist. For this a new getEntity method has been overriden with a checkIfNotExists boolean parameter. The original signature has been preserved, and will call the new one with checkIfNotExists=true, to ensure that the default behaviour is the same as it used to be.

---
M src/org/openbravo/base/model/ModelProvider.java
---
(0071725)
hgbot   
2014-11-17 18:09   
Repository: erp/devel/pi
Changeset: c77d6ec09d26a627f700bcd140454ad26052e7ca
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Fri Nov 07 15:09:23 2014 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/c77d6ec09d26a627f700bcd140454ad26052e7ca [^]

Fixes issue 28119: Prevents potential NPE in DataSourceServiceProvider

The original problem was that is potentially possible to set call the setEntity method of a null DataSourceService. Now it is not possible, because that method will only be invoked after the DataSourceService has been properly initialized.

---
M modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
---
(0071726)
hgbot   
2014-11-17 18:09   
Repository: erp/devel/pi
Changeset: 305f5c29bb31609710dd2d0f8951c87028b35ebc
Author: Augusto Mauch <augusto.mauch <at> openbravo.com>
Date: Sun Nov 09 23:42:50 2014 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/305f5c29bb31609710dd2d0f8951c87028b35ebc [^]

Related with issue 28119: Further refactoring

The code that retrieved a datasource from the datasource id, datasource name and table name has been moved to the methods getDataSourceFromDataSourceId, getDataSourceFromDataSourceName and getDataSourceFromTableName respectively.

---
M modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServiceProvider.java
---
(0071727)
AugustoMauch   
2014-11-17 18:17   
Tested in Try with success
(0071728)
AugustoMauch   
2014-11-17 18:18   
The code has been refactored. After refactoring the code, it was clear that the actual fix consisted in setting the entity to the DataSourceService only if one was available.
(0071937)
alostale   
2014-11-24 13:44   
code reviewed

tested acquiring DS with the different ways:
-By its ID
-By its Name
-By table name
(0073063)
hudsonbot   
2014-12-30 23: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/6525fe229e06 [^]
Maturity status: Test
(0073064)
hudsonbot   
2014-12-30 23: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/6525fe229e06 [^]
Maturity status: Test
(0073065)
hudsonbot   
2014-12-30 23: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/6525fe229e06 [^]
Maturity status: Test
(0073066)
hudsonbot   
2014-12-30 23: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/6525fe229e06 [^]
Maturity status: Test
(0073067)
hudsonbot   
2014-12-30 23: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/6525fe229e06 [^]
Maturity status: Test