Skip to content

[Formatter] Javadoc formatter sometimes incorrectly encodes @ to @ inside {@code} blocks #4874

@ryanpinter

Description

@ryanpinter

The formatter incorrectly encodes certain @ symbols that are included in <pre> {@code javadoc blocks. I am not sure the rules for encoding the @ on annotations, it doesn't appear to break anything but encoding it on a {@code does break the javadoc rendering.

Possibly related to: #2071

Reproduction Input:

  /**
   * Example showing formatter bug with {@code @} in pre blocks.
   *
   * <pre>
   * {@code
   * @MyAnnotation
   * public class Example {
   *
   *     @AnotherAnnotation
   *     private String field;
   * }
   * }
   * </pre>
   */
  public interface ExampleService {

      /**
       * Another method with annotation in javadoc.
       *
       * <pre>
       * {@code
       * @Override
       * public void doSomething() {
       *     // implementation
       * }
       * }
       * </pre>
       */
      void doSomething();
  }

With "Enable Classic Javadoc formatting" : False
With "Format Java code snippets inside 'pre' tags": False
Result: No Change


With "Enable Classic Javadoc formatting" : True
With "Format Java code snippets inside 'pre' tags": False
Result: @'s on some Annotations are converted to &#64;

/**
 * Example showing formatter bug with {@code @} in pre blocks.
 *
 * <pre>
 * {@code
 * &#64;MyAnnotation     <--- Possible error
 * public class Example {
 *
 *     @AnotherAnnotation    <--- Why did this not get encoded
 *     private String field;
 * }
 * }
 * </pre>
 */
public interface ExampleService {
	/**
	 * Another method with annotation in javadoc.
	 *
	 * <pre>
	 * {@code
	 * &#64;Override    <--- Possible error
	 * public void doSomething() {
	 *     // implementation
	 * }
	 * }
	 * </pre>
	 */
	void doSomething();
}

With "Enable Classic Javadoc formatting" : True
With "Format Java code snippets inside 'pre' tags": True
Result: @'s on some Annotations and some {@code are converted to &#64;

/**
 * Example showing formatter bug with {@code @} in pre blocks.
 *
 * <pre>
 * {
 * 	&#64;code    <--- Definitive error
 * 	&#64;MyAnnotation
 * 	public class Example {
 * 		@AnotherAnnotation
 * 		private String field;
 * 	}
 * }
 * </pre>
 */
public interface ExampleService {
	/**
	 * Another method with annotation in javadoc.
	 *
	 * <pre>
	 * {@code
	 * @Override
	 * public void doSomething() {
	 * 	// implementation
	 * }
	 * }
	 * </pre>
	 */
	void doSomething();
}

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