Uploaded image for project: 'DeltaSpike'
  1. DeltaSpike
  2. DELTASPIKE-1333

Support default methods in interface based configuration

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.8.1
    • Fix Version/s: None
    • Component/s: Configuration
    • Labels:
      None
    • Environment:
      Java 8, DeltaSpike 1.8.1

      Description

      I wanted to implement a default method in one of my configuration methods as a simple way to configure a Duration:

      @Configuration
      interface CacheConfig {
        @ConfigProperty(name = "cache.lifetime", defaultValue = "P1D")
        String cacheLifetime();
      
        default Duration getCacheLifetimeDuration() {
          try {
             return Duration.parse(cacheLifetime());
          } catch (DateTimeParseException e) {
              ...
        }
      }
      

      However, a runtime I get the error

      java.lang.UnsupportedOperationException: public default java.time.Duration com.example.CacheConfig.getLifetimeDuration() doesn't have @ConfigProperty and therefore is illegal

      It would be nice if default methods were not processed.

        Attachments

          Activity

            People

            • Assignee:
              struberg Mark Struberg
              Reporter:
              niels@harremoes.dk Niels Ull Harremoes
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

                Estimated:
                Original Estimate - 4h
                4h
                Remaining:
                Remaining Estimate - 4h
                4h
                Logged:
                Time Spent - Not Specified
                Not Specified