Skip to content

Commit c7e5e7b

Browse files
authored
Tweaks to record binding (#7849)
## Rationale Claude had some late-breaking suggestions for record binding, primarily if validate() is implemented (not currently, but could be added in the future) then propagating new Object() as the target would result in a ClassCastException. Note that, if a record is used, getView() in the reshow case needs to handle a null target. ## Related Pull Requests - #7837
1 parent 3687d43 commit c7e5e7b

5 files changed

Lines changed: 8 additions & 7 deletions

File tree

api/src/org/labkey/api/action/BaseApiAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private FormAndErrors<FORM> defaultPopulateForm() throws Exception
341341
saveRequestedApiVersion(getViewContext().getRequest(), null);
342342

343343
BindException errors = defaultBindParameters(getPropertyValues());
344-
FORM form = (FORM)errors.getTarget();
344+
FORM form = (errors.hasErrors() && getCommandClass().isRecord()) ? null : (FORM) errors.getTarget();
345345

346346
return new FormAndErrors<>(form, errors);
347347
}
@@ -468,7 +468,8 @@ private FormAndErrors<FORM> populateJSONObjectForm() throws Exception
468468
{
469469
PropertyValues values = null == jsonObj ? new MutablePropertyValues() : new JsonPropertyValues(jsonObj);
470470
BindException errors = defaultBindParameters(values);
471-
return new FormAndErrors<>((FORM)errors.getTarget(), errors);
471+
FORM form = errors.hasErrors() ? null : (FORM) errors.getTarget();
472+
return new FormAndErrors<>(form, errors);
472473
}
473474

474475
FORM form = getCommand();

api/src/org/labkey/api/action/FormViewAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public final ModelAndView handleRequest() throws Exception
6565
try (Timing ignored = MiniProfiler.step("bind"))
6666
{
6767
errors = bindParameters(getPropertyValues());
68-
form = (FORM)errors.getTarget();
68+
form = (errors.hasErrors() && getCommandClass().isRecord()) ? null : (FORM) errors.getTarget();
6969
}
7070

7171
return handleRequest(form, errors);

api/src/org/labkey/api/data/RecordFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public RecordFactory(Class<K> clazz)
7575
}
7676
catch (ConversionException e)
7777
{
78-
throw new IllegalArgumentException("Failed to convert property value of type '" + value.getClass().getName() + "' to required type '" + p.getType() + "' for property '" + p.getName() + "'; " + e.getMessage());
78+
throw new IllegalArgumentException("Failed to convert property value of type '" + value.getClass().getName() + "' to required type '" + p.getType().getName() + "' for property '" + p.getName() + "'; " + e.getMessage());
7979
}
8080
}).toArray();
8181

@@ -95,7 +95,7 @@ public RecordFactory(Class<K> clazz)
9595
throw e; // Unclear what the problem is, so just re-throw
9696
if (missingPrimitiveParameters.size() == 1)
9797
throw new IllegalArgumentException("Primitive parameter \"" + missingPrimitiveParameters.getFirst() + "\" is required");
98-
throw new IllegalArgumentException("One or more primitive parameters are missing. Primitive parameters include: " + missingPrimitiveParameters);
98+
throw new IllegalArgumentException("Primitive parameters are missing: " + missingPrimitiveParameters);
9999
}
100100
catch (InstantiationException | IllegalAccessException | InvocationTargetException e)
101101
{

api/src/org/labkey/api/security/roles/EditorRole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public class EditorRole extends EditorWithoutDeleteRole
2626
{
27-
protected static Collection<Class<? extends Permission>> PERMISSIONS = Stream.concat(
27+
static final Collection<Class<? extends Permission>> PERMISSIONS = Stream.concat(
2828
EditorWithoutDeleteRole.PERMISSIONS.stream(),
2929
Stream.of(
3030
DeletePermission.class,

api/src/org/labkey/api/security/roles/EditorWithoutDeleteRole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
public class EditorWithoutDeleteRole extends AbstractRole
3535
{
36-
protected static Collection<Class<? extends Permission>> PERMISSIONS = Stream.concat(
36+
static final Collection<Class<? extends Permission>> PERMISSIONS = Stream.concat(
3737
AuthorRole.PERMISSIONS.stream(),
3838
Stream.of(
3939
EditSharedReportPermission.class,

0 commit comments

Comments
 (0)