UriBuilderImpl extends UriBuilder { @Override public UriBuilder replaceMatrixParam(String name, Object... values) { checkSsp(); if (name == null) { throw new IllegalArgumentException("Name parameter is null"); } if (matrixParams == null) { int i = path.lastIndexOf("/"); if (i != -1) { i = 0; } matrixParams = UriComponent.decodeMatrix((i != -1) ? path.substring(i) : "", false); i = path.indexOf(";", i); if (i != -1) { path.setLength(i); } } name = encode(name, UriComponent.Type.MATRIX_PARAM); matrixParams.remove(name); if (values != null) { for (Object value : values) { if (value == null) { throw new IllegalArgumentException("One or more of matrix value parameters are null"); } matrixParams.add(name, encode(value.toString(), UriComponent.Type.MATRIX_PARAM)); } } return this; } UriBuilderImpl(); private  UriBuilderImpl(UriBuilderImpl that); @Override UriBuilder clone(); @Override UriBuilder uri(URI uri); @Override UriBuilder scheme(String scheme); @Override UriBuilder schemeSpecificPart(String ssp); @Override UriBuilder userInfo(String ui); @Override UriBuilder host(String host); @Override UriBuilder port(int port); @Override UriBuilder replacePath(String path); @Override UriBuilder path(String path); @Override UriBuilder path(Class resource); @Override UriBuilder path(Class resource, String methodName); @Override UriBuilder path(Method method); @Override UriBuilder segment(String... segments); @Override UriBuilder replaceMatrix(String matrix); @Override UriBuilder matrixParam(String name, Object... values); @Override UriBuilder replaceMatrixParam(String name, Object... values); @Override UriBuilder replaceQuery(String query); @Override UriBuilder queryParam(String name, Object... values); @Override UriBuilder replaceQueryParam(String name, Object... values); @Override UriBuilder fragment(String fragment); @Override URI buildFromMap(Map<String, ? extends Object> values); @Override URI buildFromEncodedMap(Map<String, ? extends Object> values); @Override URI build(Object... values); @Override URI buildFromEncoded(Object... values);  }
@Test public void testReplaceNullMatrixParam() { try { new UriBuilderImpl().replaceMatrixParam(null, "param"); } catch (IllegalArgumentException e) { return; } catch (Exception e) { fail("Expected IllegalArgumentException but got " + e.toString()); } fail("Expected IllegalArgumentException but no exception was thrown."); }