Skip to content

Noun method names in XmlNode #11582

Closed as not planned
Closed as not planned

Description

@elharo

Affected version

4.x

Bug description

For inobvious reasons methods that follow Java conventions like getChild and getValue have been deprecated and replaced with methods that don't like child() and value(). This is confusing and unnecessary churn. Revert this.

One can argue about the wisdom of Java's well-established naming conventions, but individual projects like Maven should not needlessly deviate from those for personal preference. It's far easier to stick with existing convention than for every project to pave its own way.

And yes, Oracle did a half-assed job when they added records to the language in Java 17 without considering the impact on naming conventions for existing code. That neither conformed to nor changed existing conventions for non-record classes and interfaces.

Activity

  1. added
    bug
    priority:blocker
    on Dec 21, 2025
  2. elharo commented on Dec 21, 2025

    @elharo
    ContributorAuthor

    Apparently I approved this one in #2150

    Not sure what I was thinking. I probably needed more coffee.

  3. removed
    priority:blocker
    on Jun 23, 2026
  4. gnodet commented on Sep 3, 2026

    @gnodet
    Contributor

    This is not a bug and the current naming is intentional. The record-accessor pattern (noun-only: name(), value(), children()) is the established convention for immutable value types in modern Java — not a personal preference deviation.

    The JDK itself has been using this pattern for interfaces and classes representing immutable/value-type objects since well before records existed:

    • java.lang.module.ModuleDescriptor (Java 9): name(), version(), requires(), exports(), packages()
    • java.lang.ProcessHandle.Info (Java 9): command(), arguments(), user()
    • java.util.stream.Collector (Java 8): supplier(), accumulator(), combiner(), finisher()
    • java.net.http.HttpResponse (Java 11): statusCode(), body(), headers(), uri()
    • java.lang.constant.ClassDesc (Java 12): packageName(), displayName()
    • java.util.ServiceLoader.Provider (Java 9): type()

    This is not something Oracle "half-assed with records in Java 17" — the convention predates records by almost a decade. Records merely formalized what the JDK was already doing: immutable data carriers use noun accessors, not getX() verb accessors. The get prefix convention is for JavaBeans — mutable objects with getters/setters.

    XmlNode is an immutable value type by contract. It has no setters, no mutation methods. The noun-accessor style correctly signals this immutability to users, which is exactly the intent of the Maven 4 API design. Several other hand-crafted API interfaces in Maven 4 follow the same pattern: PathType.name(), PathType.id(), Lifecycle.Phase.name(), OsService.name(), CIInfo.name().

    Flipping the deprecation direction would:

    1. Break the migration path for users who already moved from getName() to name() as the deprecation warnings directed
    2. Create inconsistency with other Maven 4 API interfaces that use the same pattern
    3. Go against the direction the JDK itself has taken for value types

    The getX() default methods exist solely as a compatibility bridge and are correctly deprecated for removal.

  5. elharo commented on Sep 3, 2026

    @elharo
    ContributorAuthor

    This dramatically overstates the case and cherry picks evidence from a few random classes. This reversal of convention simply did not happen in Java 8. Maybe it started to pick up around Java 11, but I simply do not think it is reasonable to claim that this is the preferred or expected convention even in Java 26. Yes, both are used today but one has an explicit mandate and design going back 30 years and one doesn't. The mistake made here was to deprecate the existing methods that are already used and impose unnecessary costs on clients because of personal preference. Unfortunately that's a mistake that's been made again and again across Maven 4 APIs. This is hardly the only example. Lots of deprecation and API churn that makes the system more complex for no particular benefit. It prioritizes the preferences of some committers over the desire of the large installed base for compatible APIs that just work. Maven 4 hasn't shipped, so all this can still be fixed, but that does require refocusing on actual user facing features instead of random changes that deliver only negative user value.

  6. gnodet commented on Sep 3, 2026

    @gnodet
    Contributor

    To be thorough, here is a more comprehensive survey of every new immutable type/interface introduced in the JDK since Java 13, looking at both noun-style and getX()-style accessors:

    Noun-style accessors (no get prefix):

    • Java 17 — RandomGeneratorFactory: name(), group(), equidistribution()
    • Java 21 — StructuredTaskScope.Subtask: state(), get(), exception()
    • Java 22 — Foreign Function & Memory API (finalized):
      • MemoryLayout: byteSize(), name(), byteAlignment()
      • MemorySegment: address(), byteSize(), scope()
      • FunctionDescriptor: argumentLayouts(), returnLayout()
      • AddressLayout: targetLayout()
    • Java 24 — Classfile API (finalized — the largest new API added to the JDK in years, dozens of interfaces, zero getX() methods):
      • ClassModel: fields(), methods(), interfaces(), flags(), superclass(), thisClass(), constantPool(), majorVersion(), minorVersion()
      • MethodModel: methodName(), methodType(), code(), flags(), parent()
      • FieldModel: fieldName(), fieldType(), flags(), parent()
      • Annotation: className(), elements()
      • TypeKind: upperBound(), slotSize()
    • Java 24 — Gatherer: initializer(), integrator(), combiner(), finisher()
    • Java 24 — MatchResult (new method): namedGroups()

    getX()-style accessors on newly introduced immutable types:

    • Java 16 — UnixDomainSocketAddress: getPath() — however, this class extends SocketAddress (Java 1.4) and follows the pre-existing InetSocketAddress.getPort()/getHostName() convention from the same hierarchy.

    That is the only counter-example found, and it is constrained by a legacy class hierarchy. Every genuinely new immutable type or interface introduced since Java 13 — unconstrained by pre-existing hierarchies — uses noun-style accessors exclusively. The Classfile API alone, finalized in JDK 24, is a massive data point: a large, carefully designed API by the OpenJDK team with fields(), not getFields(); methodName(), not getMethodName().

    This is not cherry-picking — it is the complete picture.

  7. gnodet commented on Sep 3, 2026

    @gnodet
    Contributor

    And for completeness, the same survey for JDK 8–12 — every new immutable type/interface introduced in this range, checking both accessor styles:

    Noun-style accessors (no get prefix):

    • Java 8 — Collector: supplier(), accumulator(), combiner(), finisher(), characteristics()
    • Java 9 — ModuleDescriptor: name(), version(), requires(), exports(), opens(), uses(), provides(), packages(), modifiers()
    • Java 9 — ModuleDescriptor.Exports: source(), targets(), modifiers()
    • Java 9 — ModuleDescriptor.Requires: name(), modifiers(), compiledVersion()
    • Java 9 — ModuleDescriptor.Provides: service(), providers()
    • Java 9 — ModuleReference: descriptor(), location()
    • Java 9 — ProcessHandle: pid(), info(), parent(), children()
    • Java 9 — ProcessHandle.Info: command(), arguments(), user(), startInstant(), totalCpuDuration(), commandLine()
    • Java 9 — ServiceLoader.Provider: type()
    • Java 11 — HttpClient: authenticator(), connectTimeout(), cookieHandler(), executor(), followRedirects(), proxy(), sslContext(), sslParameters(), version()
    • Java 11 — HttpRequest: method(), uri(), headers(), bodyPublisher(), expectContinue(), timeout(), version()
    • Java 11 — HttpResponse: statusCode(), body(), headers(), uri(), version()
    • Java 12 — ClassDesc: packageName(), displayName()
    • Java 12 — MethodTypeDesc: returnType(), parameterCount(), parameterList(), parameterArray()
    • Java 12 — DirectMethodHandleDesc: kind(), methodName(), owner(), lookupDescriptor(), refKind()
    • Java 12 — DynamicConstantDesc: bootstrapArgs(), bootstrapMethod(), constantName(), constantType()

    getX()-style accessors on newly introduced immutable types:

    • Java 9 — StackWalker.StackFrame: getClassName(), getMethodName(), getFileName(), getLineNumber(), getByteCodeIndex() — however, this interface was deliberately designed to mirror StackTraceElement (Java 1.4), and even provides a toStackTraceElement() conversion method. The naming follows the pre-existing class it mirrors.

    So across the entire JDK 8–25 range, the only two counter-examples are StackWalker.StackFrame (mirrors StackTraceElement from Java 1.4) and UnixDomainSocketAddress (extends SocketAddress from Java 1.4). Both are constrained by pre-existing APIs. Every genuinely new immutable type — unconstrained by legacy — uses noun-style accessors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions