Skip to content

Commit

Permalink
fix NPE on DocumentInterfaceWrapperHelper.getValue
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Apr 23, 2017
1 parent 66f1540 commit c904343
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand Down Expand Up @@ -102,7 +102,7 @@ else if (model instanceof IDocumentAware)
document = ((IDocumentAware)model).getDocument();
useOldValuesDefault = false;
}

if (document == null)
{
final DocumentInterfaceWrapper wrapper = getWrapper(model);
Expand Down Expand Up @@ -179,7 +179,7 @@ else if (model instanceof IDocumentAware)
* @param model
* @return {@link DocumentInterfaceWrapper} or null if no {@link DocumentInterfaceWrapper} can be extracted from given model
*/
/* package */static DocumentInterfaceWrapper getWrapper(final Object model)
private static DocumentInterfaceWrapper getWrapper(final Object model)
{
if (model == null)
{
Expand All @@ -204,6 +204,50 @@ else if (model instanceof DocumentInterfaceWrapper)
return null;
}

/* package */static DocumentInterfaceWrapper getOrCreateWrapper(final Object model)
{
if (model == null)
{
return null;
}

//
// Try to get the wrapper directly
if (Proxy.isProxyClass(model.getClass()))
{
final InvocationHandler ih = Proxy.getInvocationHandler(model);
if (ih instanceof DocumentInterfaceWrapper)
{
final DocumentInterfaceWrapper wrapper = (DocumentInterfaceWrapper)ih;
return wrapper;
}
return null;
}
else if (model instanceof DocumentInterfaceWrapper)
{
return (DocumentInterfaceWrapper)model;
}

//
// Try getting the document and create a wrapper for it
if (model instanceof Document)
{
final Document document = (Document)model;
final boolean useOldValues = false;
return new DocumentInterfaceWrapper(document, useOldValues);
}
else if (model instanceof IDocumentAware)
{
final Document document = ((IDocumentAware)model).getDocument();
final boolean useOldValues = false;
return new DocumentInterfaceWrapper(document, useOldValues);
}

//
// Wrapper could not be found or create
throw new IllegalArgumentException("Cannot get or create the " + DocumentInterfaceWrapper.class + " from " + model);
}

public static int getWindowNo(final Object model)
{
final Document document = getDocument(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ public boolean isNew(final Object model)
@Override
public <T> T getValue(final Object model, final String columnName, final boolean throwExIfColumnNotFound, final boolean useOverrideColumnIfAvailable)
{
final DocumentInterfaceWrapper wrapper = DocumentInterfaceWrapper.getOrCreateWrapper(model);

//
// Get <columnName>_Override's value, if any
final DocumentInterfaceWrapper wrapper = DocumentInterfaceWrapper.getWrapper(model);
if (useOverrideColumnIfAvailable)
{
final T value = getValueOverrideOrNull(wrapper, columnName);
Expand Down

0 comments on commit c904343

Please sign in to comment.