Dhairya-007 opened a new pull request, #29472:
URL: https://github.com/apache/camel/pull/29472

   ## Problem
   
   The `mediaSize` option is documented as *"Sets the stationary as defined by 
enumeration names in the javax.print.attribute.standard.MediaSizeName API. ... 
The value's case is ignored, e.g. values of iso_a4 and ISO_A4 may be used."*
   
   Only the `iso` prefix was actually matched case-insensitively:
   
   ```java
   } else if (size.regionMatches(true, 0, "iso", 0, "iso".length())) {   // 
ignores case
   } else if (size.startsWith("jis")) {                                 // does 
not
   } else if (size.startsWith("na")) {                                  // does 
not
   ```
   
   So an uppercase `jis`/`na` value skipped its own table and fell through to 
`selectMediaSizeNameOther`, which matched nothing and returned `null`. A value 
is also only looked up in the table its prefix names, so sizes that live in the 
catch-all table but start with a family prefix, such as `iso_designated_long`, 
returned `null` as well.
   
   `PrinterProducer.assignPrintAttributes` passes the result straight on:
   
   ```java
   printRequestAttributeSet.add(config.getMediaSizeName());
   ```
   
   `HashPrintRequestAttributeSet.add` rejects `null`, so these values fail with 
a bare `NullPointerException` and no indication of which option was wrong. 
Notably `mediaSize=NA_LETTER` is the value used in this component's own 
documentation (`lpr-component.adoc`), and the existing tests that would have 
covered this are `@Disabled`/`@DisabledOnOs` because they need a real printer.
   
   Verified against the current code before the change:
   
   ```
   na-letter              -> na-letter    resolved
   NA_LETTER              -> null         null -> NPE in assignPrintAttributes()
   JIS_B4                 -> null         null -> NPE in assignPrintAttributes()
   iso_designated_long    -> null         null -> NPE in assignPrintAttributes()
   ```
   
   ## Change
   
   Resolution moves into a single `MediaSizeAssigner.selectMediaSizeName` entry 
point that
   
   * matches the family prefix ignoring case,
   * accepts `-` in place of `_`, so the option's documented default 
`na-letter` also works when given explicitly,
   * falls back to the remaining sizes when the family table has no match, and
   * reports an unrecognised value as `IllegalArgumentException: Unknown 
mediaSize: <value>` instead of letting `null` reach the print request.
   
   The four lookup methods now keep their result in a local variable instead of 
a shared field, so an unmatched value cannot return what an earlier call left 
behind.
   
   `PrinterConfiguration.assignMediaSize` keeps its existing behaviour of 
defaulting to `NA_LETTER` when the option is not set at all.
   
   ## Tests
   
   `MediaSizeAssignerTest` covers lowercase names, uppercase names, hyphenated 
names, a size outside the family its prefix suggests, and rejection of an 
unknown value. The module's tests use JUnit assertions, so the new test does 
too.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to