Skip to content

ClassNotFoundException during Rule Validation #94

Description

@nils-christian

Hi,

We are getting a ClassNotFoundException while executing a custom rule. Please take a look at the following rule (I simplified the condition):

public static final ArchRule MY_RULE = methods( )
			.should( followMyRule( ) )
			.allowEmptyShould( true );

private static ArchCondition<JavaMethod> followMyRule( ) {
	return new ArchCondition<>( "follow my rule" ) {

		@Override
		public void check( final JavaMethod method, final ConditionEvents events ) {
			final ExceptionHandler exceptionHandlerAnnotation = method.getAnnotationOfType( ExceptionHandler.class );
			if ( exceptionHandlerAnnotation.exception( ).length > 0 || exceptionHandlerAnnotation.value( ).length > 0 ) {
				events.add( SimpleConditionEvent.violated( method, method.getFullName( ) ) );
			}
		}
	};
}

The ExceptionHandler annotation is imported from spring-web 7.0.3.

Validating the rule with the following two domain classes leads to the mentioned exception.

public class MyException extends RuntimeException {
	public MyException( String message ) {
		super( message );
	}
}

public class MyClass {

	@ExceptionHandler( { MyException.class } )
	private void handleMyException( final MyException exception ) {
	}

}

This is the corresponding stack trace:

Caused by: org.apache.maven.plugin.MojoFailureException: ArchUnit Maven plugin reported architecture failures listed below :Rule Violated - org.example.MyRules
java.lang.ClassNotFoundException: org.example.MyException
at com.societegenerale.commons.plugin.maven.ArchUnitMojo.execute (ArchUnitMojo.java:114)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)

It does not occur when using a build-in exception (e.g. NullPointerException) and the execution via the plain ArchUnit API does not raise an exception either.

final ClassFileImporter classFileImporter = new ClassFileImporter( );
final JavaClasses javaClasses = classFileImporter.importClasses( MyClass.class, MyException.class );

final EvaluationResult evaluationResult = MyRules.MY_RULE.evaluate( javaClasses );
evaluationResult.handleViolations( ( final Collection<JavaMember> violatingObjects, final String message ) -> System.out.println( violatingObjects ) );

Thus I assume that the issue is somehow located in the ArchUnit Maven plugin.

Thank you and best regards

Nils

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