damnhandy / Handy-URI-Templates

A Java URI Template processor implementing RFC6570
https://damnhandy.github.io/Handy-URI-Templates/
Other
203 stars 37 forks source link

Throws error on empty map #49

Closed drdamour closed 8 years ago

drdamour commented 8 years ago

template of something like

        UriTemplate.fromTemplate("http://example.com/{?keys*}")
            .set("keys", Collections.emptyMap())
            .expand();

throws

com.damnhandy.uri.template.VarExploderException: java.lang.IllegalAccessException: Class com.damnhandy.uri.template.DefaultVarExploder can not access a member of class java.util.Collections$EmptyMap with modifiers "public"
    at com.damnhandy.uri.template.DefaultVarExploder.getValue(DefaultVarExploder.java:296)
    at com.damnhandy.uri.template.DefaultVarExploder.inspectGetters(DefaultVarExploder.java:197)
    at com.damnhandy.uri.template.DefaultVarExploder.initValues(DefaultVarExploder.java:139)
    at com.damnhandy.uri.template.DefaultVarExploder.setSource(DefaultVarExploder.java:118)
    at com.damnhandy.uri.template.DefaultVarExploder.<init>(DefaultVarExploder.java:97)
    at com.damnhandy.uri.template.impl.VarExploderFactory.getExploder(VarExploderFactory.java:54)
    at com.damnhandy.uri.template.UriTemplate.expandVariables(UriTemplate.java:673)
    at com.damnhandy.uri.template.UriTemplate.expressionReplacementString(UriTemplate.java:593)
    at com.damnhandy.uri.template.UriTemplate.expand(UriTemplate.java:426)
    at com.bodybuilding.commerce.catalog.CatalogLinkBuilderTest.linkToSelectWithEmptySelections(CatalogLinkBuilderTest.java:252)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.IllegalAccessException: Class com.damnhandy.uri.template.DefaultVarExploder can not access a member of class java.util.Collections$EmptyMap with modifiers "public"
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:296)
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:288)
    at com.damnhandy.uri.template.DefaultVarExploder.getValue(DefaultVarExploder.java:288)

this worked in 2.0.2

damnhandy commented 8 years ago

I just pushed a fix for this in 2.1.4-SNAPSHOT. If a moment, please test it out to verify and I'll cut the release tonight.

drdamour commented 8 years ago

looks good

damnhandy commented 8 years ago

Done. 2.1.4 is now released.