Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit fade58e

Browse files
committed
skip unsupported mvc route attributes fix jooby-project#568
1 parent 70a2597 commit fade58e

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

jooby/src/main/java/org/jooby/Jooby.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -634,64 +634,64 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
634634
/**
635635
* Keep track of routes.
636636
*/
637-
private Set<Object> bag = new LinkedHashSet<>();
637+
private transient Set<Object> bag = new LinkedHashSet<>();
638638

639639
/**
640640
* The override config. Optional.
641641
*/
642-
private Config srcconf;
642+
private transient Config srcconf;
643643

644-
private final AtomicBoolean started = new AtomicBoolean(false);
644+
private final transient AtomicBoolean started = new AtomicBoolean(false);
645645

646646
/** Keep the global injector instance. */
647-
private Injector injector;
647+
private transient Injector injector;
648648

649649
/** Session store. */
650-
private Session.Definition session = new Session.Definition(Session.Mem.class);
650+
private transient Session.Definition session = new Session.Definition(Session.Mem.class);
651651

652652
/** Env builder. */
653-
private Env.Builder env = Env.DEFAULT;
653+
private transient Env.Builder env = Env.DEFAULT;
654654

655655
/** Route's prefix. */
656-
private String prefix;
656+
private transient String prefix;
657657

658658
/** startup callback . */
659-
private List<CheckedConsumer<Registry>> onStart = new ArrayList<>();
659+
private transient List<CheckedConsumer<Registry>> onStart = new ArrayList<>();
660660

661661
/** stop callback . */
662-
private List<CheckedConsumer<Registry>> onStop = new ArrayList<>();
662+
private transient List<CheckedConsumer<Registry>> onStop = new ArrayList<>();
663663

664664
/** Mappers . */
665665
@SuppressWarnings("rawtypes")
666-
private Mapper mapper;
666+
private transient Mapper mapper;
667667

668668
/** Don't add same mapper twice . */
669-
private Set<String> mappers = new HashSet<>();
669+
private transient Set<String> mappers = new HashSet<>();
670670

671671
/** Bean parser . */
672-
private Optional<Parser> beanParser = Optional.empty();
672+
private transient Optional<Parser> beanParser = Optional.empty();
673673

674-
private ServerLookup server = new ServerLookup();
674+
private transient ServerLookup server = new ServerLookup();
675675

676-
private String dateFormat;
676+
private transient String dateFormat;
677677

678-
private Charset charset;
678+
private transient Charset charset;
679679

680-
private String[] languages;
680+
private transient String[] languages;
681681

682-
private ZoneId zoneId;
682+
private transient ZoneId zoneId;
683683

684-
private Integer port;
684+
private transient Integer port;
685685

686-
private Integer securePort;
686+
private transient Integer securePort;
687687

688-
private String numberFormat;
688+
private transient String numberFormat;
689689

690-
private boolean http2;
690+
private transient boolean http2;
691691

692-
private List<Consumer<Binder>> executors = new ArrayList<>();
692+
private transient List<Consumer<Binder>> executors = new ArrayList<>();
693693

694-
private boolean defaultExecSet;
694+
private transient boolean defaultExecSet;
695695

696696
/**
697697
* Creates a new {@link Jooby} application.

jooby/src/main/java/org/jooby/Route.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,19 +1229,20 @@ public Definition attr(final String name, final Object value) {
12291229
requireNonNull(name, "Attribute name is required.");
12301230
requireNonNull(value, "Attribute value is required.");
12311231

1232-
validate(value);
1233-
attributes.put(name, value);
1232+
if (valid(value)) {
1233+
attributes.put(name, value);
1234+
}
12341235
return this;
12351236
}
12361237

1237-
private boolean validate(final Object value) {
1238+
private boolean valid(final Object value) {
12381239
return Match(value).option(
12391240
Case(v -> Primitives.isWrapperType(Primitives.wrap(v.getClass())), true),
12401241
Case(instanceOf(String.class), true),
12411242
Case(instanceOf(Enum.class), true),
12421243
Case(instanceOf(Class.class), true),
1243-
Case(c -> c.getClass().isArray(), v -> validate(Array.get(v, 0))))
1244-
.getOrElseThrow(() -> new IllegalArgumentException("Unsupported attribute: " + value));
1244+
Case(c -> c.getClass().isArray(), v -> valid(Array.get(v, 0))))
1245+
.getOrElse(false);
12451246
}
12461247

12471248
/**
@@ -1623,7 +1624,9 @@ public static Route unwrap(final Route route) {
16231624
* The most advanced route handler which let you decided if the next route handler in the chain
16241625
* can be executed or not. Example of filters are:
16251626
*
1626-
* <p>Auth handler example:</p>
1627+
* <p>
1628+
* Auth handler example:
1629+
* </p>
16271630
*
16281631
* <pre>
16291632
* String token = req.header("token").value();
@@ -1637,7 +1640,9 @@ public static Route unwrap(final Route route) {
16371640
* }
16381641
* </pre>
16391642
*
1640-
* <p>Logging/Around handler example:</p>
1643+
* <p>
1644+
* Logging/Around handler example:
1645+
* </p>
16411646
*
16421647
* <pre>
16431648
* long start = System.currentTimeMillis();

jooby/src/test/java/org/jooby/RouteDefinitionTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jooby;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNull;
45
import static org.junit.Assert.assertTrue;
56

67
import java.util.Arrays;
@@ -321,7 +322,7 @@ public void src() throws Exception {
321322
Function<String, Route.Definition> route = path -> new Route.Definition("*", path, () -> null);
322323
Route.Definition r = route.apply("/");
323324

324-
assertEquals("org.jooby.RouteDefinitionTest:321", r.source().toString());
325+
assertEquals("org.jooby.RouteDefinitionTest:322", r.source().toString());
325326
}
326327

327328
@Test
@@ -345,10 +346,12 @@ public void attrsArray() throws Exception {
345346
assertTrue(Arrays.equals(new int[]{7 }, (int[]) r.attr("i")));
346347
}
347348

348-
@Test(expected = IllegalArgumentException.class)
349+
@Test
349350
public void attrUnsupportedType() throws Exception {
350351
Function<String, Route.Definition> route = path -> new Route.Definition("*", path, () -> null);
351-
route.apply("/").attr("i", new Object());
352+
Route.Definition r = route.apply("/");
353+
r.attr("i", new Object());
354+
assertNull(r.attr("i"));
352355
}
353356

354357
}

0 commit comments

Comments
 (0)