Skip to content

ArchUnit: how can one silence references to arrays of basic types for method mayOnlyAccessLayers(...)? #887

@mmoser18

Description

@mmoser18

For a big GWT-based application I am defining an architecture check to prevent that our junior programmers accidentally reference classes that are not GWT-serializable and the resulting objects then can not make it "over the wire" (which then throws exceptions at runtime).

For this I am using a layer-check like so:

	@ArchTest
	void checkGWTAccess(JavaClasses classes) {
		LayeredArchitecture layers = Architectures.layeredArchitecture()
			.layer("Client").definedBy("..client..")
			.layer("Shared").definedBy("..shared..")
			... <many entries omitted here> ...
			;

		ArchRule rule = layers
			.whereLayer("Client").mayOnlyAccessLayers("Shared", "DomDtos", "DomBase", "DomConfig",  								
			                                          ... <many entries omitted here> ...
			                                         );
			;
		rule.check(classes);

"In principle" this works ok EXCEPT that I am still getting errors for all fields that are arrays of basic types or collections of basic types (i.e. e.g. int[] digits;, char[] buffer;, List<Integer> allowedValues;) as well as methods returning such arrays or collections (i.e. e.g. int[] methodA(...) {...}, String[] methodB(...) {...}, List<Character> methodC(...) {...}, etc.).

These error read e.g.:

Field <com.example.client.ui.components.converter.TimeFieldConverter.timeNumberDigits> has type <[I> in (TimeFieldConverter.java:0)

IMHO this is a bug in ArchUnit. I can not fancy any reason arrays of basic types should possibly violate any layer-check rule.

In case this is NOT a bug:
How can one exclude these types from a <layer>.mayOnlyAccessLayers(...)-check?

Or - alternatively - can one include these types to the list of allowed layers (if it's possible to identify the and/or declare them as "layer")?

The purpose is simply, to avoid getting any rule violations for these references, so that the tests run green.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions