Skip to content

Webindex PageLoader null handling #7

@kennethmcfarland

Description

@kennethmcfarland

webindex.data.fluo.PageLoader does not check for null inputs. When dereferencing the object to see if it is empty it doesn't first check to make sure the object exists. I wrote a simple test to show this below.

This is line 45 - 50 that shows why it happens

public static PageLoader updatePage(Page page) {
    Preconditions.checkArgument(!page.isEmpty(), "Page cannot be empty");
    PageLoader update = new PageLoader();
    update.action = Action.UPDATE;
    update.page = page;
    return update;
  }
package webindex.fluo;

import org.junit.Test;

import webindex.core.models.Page;
import webindex.data.fluo.PageLoader;

public class PageLoaderTest {

	@Test
	public void testNullPage() {
		Page p = null;
		PageLoader loader = PageLoader.updatePage(p);
	}
	
	@Test(expected = IllegalArgumentException.class)
	public void testEmptyPageThrowsIllegalArgument() {
		Page p = Page.EMPTY;
		PageLoader loader = PageLoader.updatePage(p);
	}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions