Skip to content

Op caching failure when using OpBuilder vs. Nil pattern #74

@gselzer

Description

@gselzer

The following JUnit test fails, but shouldn't:

	@Test
	public void testFoo() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {

		DefaultOpEnvironment defOpEnv = getDefaultOpEnv();

		// Put the Op in the cache
		Producer<String> foo = defOpEnv.op("test.basicOp").input().outType(String.class).producer();

		// Call the Op a different way, but with the same args -> should be a cache hit
		Nil<Producer<String>> specialType = new Nil<>() {};
		Nil<String> outType = Nil.of(String.class);
		Producer<String> bar = defOpEnv.op("test.basicOp", specialType, new Nil[] {}, outType);

		// Assert only one cache entry
		Map<MatchingConditions, OpInstance> opCache = getOpCache(defOpEnv);
		Assert.assertEquals(1, opCache.size());
	}

This breaks because the MatchingConditions of the two calls return different hashCodes, due to the differences in the underlying OpRef. These differences are due to the ParameterizedType implementations used to create the specialType:

  • The first (i.e. OpBuilder) method calls the TypeService under the hood. This results in a Types.TypeUtils.ParameterizedTypeImpl under the hood.
  • The second method uses a Types.ParameterizedTypeImpl (from Guava) under the hood.

As these implementations of ParameterizedType produce their hashcodes differently, the resulting DefaultOpRefs have different hashcodes.

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