Changeset 6930


Ignore:
Timestamp:
Jun 10, 2015, 11:41:55 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1949: NullPointerException? when merging item lists

The problem was that the current context is used to store some temporary information while editing items (eg. the current item list). When selecting a saved preset, it replaces the current context and also all temporary objects stored in it, thereby causing the NullPointerException when trying to use it later. All list pages are potentially affected by the same problem.

The fix is to copy temporary objects from the current context to the preset when it is loaded.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/Base.java

    r6921 r6930  
    806806  public static ItemContext loadContext(SessionControl sc, int contextId, ItemContext defaultContext)
    807807  {
    808     ItemContext cc = sc.loadContext(contextId);
     808    ItemContext cc = sc.loadContext(contextId, true);
    809809    // Copy default columns so it is always available in other contexts
    810810    if (defaultContext != null && cc != null)
  • trunk/src/core/net/sf/basedb/core/ItemContext.java

    r6896 r6930  
    14041404  {
    14051405    return objects == null ? null : objects.remove(name);
     1406  }
     1407 
     1408  /**
     1409    Copies all objects and temporary filters from this context
     1410    to another context.
     1411    @since 3.6
     1412  */
     1413  public void copyObjectsAndTemporaryFilters(ItemContext other)
     1414  {
     1415    if (objects != null || objects.size() > 0)
     1416    {
     1417      if (other.objects == null) other.objects = new HashMap<String, Object>();
     1418      other.objects.putAll(objects);
     1419    }
     1420    for (PropertyFilterPair filter : propertyFilters.values())
     1421    {
     1422      if (filter.temporary != null)
     1423      {
     1424        other.setPropertyFilter(filter.temporary);
     1425      }
     1426    }
    14061427  }
    14071428
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r6688 r6930  
    13811381    throws NotLoggedInException, BaseException
    13821382  {
     1383    return loadContext(contextId, false);
     1384  }
     1385 
     1386  /**
     1387    Load a context and make it the current context, optionally copying
     1388    temporary filters and objects from the current context to the loaded context.
     1389    If a saved context with the specified ID
     1390    doesn't exists, or if the logged in user does't have permission to read it,
     1391    null is returned and the current context is left unchanged.
     1392   
     1393    @param contextId The ID of the context to load
     1394    @return An <code>ItemContext</code> object or null
     1395    @throws NotLoggedInException If no user is logged in
     1396    @throws BaseException If there is another error
     1397    @see #saveCurrentContextAs(Item, String, boolean, boolean)
     1398    @see #getContextNames(Item)
     1399    @since 3.6
     1400  */
     1401  public ItemContext loadContext(int contextId, boolean copyTemporaryObjects)
     1402    throws NotLoggedInException, BaseException
     1403  {
    13831404    updateLastAccess();
    13841405    if (!isLoggedIn())
     
    13901411    {
    13911412      ContextKey contextKey = new ContextKey(context.getItemType(), context.getSubContext());
    1392       currentContexts.put(contextKey, context);
     1413      ItemContext old = currentContexts.put(contextKey, context);
     1414      if (copyTemporaryObjects && old != null)
     1415      {
     1416        old.copyObjectsAndTemporaryFilters(context);
     1417      }
    13931418    }
    13941419    return context;
    13951420  }
     1421
    13961422 
    13971423  /**
Note: See TracChangeset for help on using the changeset viewer.