Skip to content

Commit

Permalink
Issue checkstyle#12681: removes serializable from violation and audit…
Browse files Browse the repository at this point in the history
… event
  • Loading branch information
rnveach committed Feb 21, 2023
1 parent 8986adb commit 1a31903
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
25 changes: 18 additions & 7 deletions src/main/java/com/puppycrawl/tools/checkstyle/api/AuditEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package com.puppycrawl.tools.checkstyle.api;

import java.util.EventObject;

/**
* Raw event for audit.
* <p>
Expand All @@ -37,11 +35,10 @@
*
* @see AuditListener
*/
public final class AuditEvent
extends EventObject {
public final class AuditEvent {

/** Record a version. */
private static final long serialVersionUID = -3774725606973812736L;
/** The object on which the Event initially occurred. */
private final Object source;
/** Filename event associated with. **/
private final String fileName;
/** Violation associated with the event. **/
Expand Down Expand Up @@ -72,13 +69,27 @@ public AuditEvent(Object src, String fileName) {
* @param src source of the event
* @param fileName file associated with the event
* @param violation the actual violation
* @throws IllegalArgumentException if {@code src} is {@code null}.
*/
public AuditEvent(Object src, String fileName, Violation violation) {
super(src);
if (src == null) {
throw new IllegalArgumentException("null source");
}

source = src;
this.fileName = fileName;
this.violation = violation;
}

/**
* The object on which the Event initially occurred.
*
* @return the object on which the Event initially occurred
*/
public Object getSource() {
return source;
}

/**
* Returns name of file being audited.
*
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/com/puppycrawl/tools/checkstyle/api/Violation.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package com.puppycrawl.tools.checkstyle.api;

import java.io.Serializable;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Locale;
Expand All @@ -32,16 +31,12 @@
* message.properties files. The underlying implementation uses
* java.text.MessageFormat.
*
* @noinspection SerializableHasSerializationMethods, ClassWithTooManyConstructors
* @noinspectionreason SerializableHasSerializationMethods - we do not serialize this class
* @noinspection ClassWithTooManyConstructors
* @noinspectionreason ClassWithTooManyConstructors - immutable nature of class requires a
* bunch of constructors
*/
public final class Violation
implements Comparable<Violation>, Serializable {

/** A unique serial version identifier. */
private static final long serialVersionUID = 5675176836184862150L;
implements Comparable<Violation> {

/** The default severity level if one is not specified. */
private static final SeverityLevel DEFAULT_SEVERITY = SeverityLevel.ERROR;
Expand All @@ -64,15 +59,7 @@ public final class Violation
/** Key for the violation format. **/
private final String key;

/**
* Arguments for MessageFormat.
*
* @noinspection NonSerializableFieldInSerializableClass
* @noinspectionreason NonSerializableFieldInSerializableClass - usage of
* 'Serializable' for this api class
* is considered as mistake now, but we do not break api without
* good reason
*/
/** Arguments for MessageFormat. */
private final Object[] args;

/** Name of the resource bundle to get violations from. **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.puppycrawl.tools.checkstyle.api;

import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

Expand All @@ -43,6 +44,16 @@ public void test() {
.isEqualTo(SeverityLevel.INFO);
}

@Test
public void testNoSource() {
final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> new AuditEvent(null),
"IllegalArgumentException expected");
assertWithMessage("Invalid exception message")
.that(ex.getMessage())
.isEqualTo("null source");
}

@Test
public void testFullConstructor() {
final Violation message = new Violation(1, 2, 3, "bundle", "key", null,
Expand Down

0 comments on commit 1a31903

Please sign in to comment.