-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip optimization for Accessors tailored by ri from different package. (
#1527) Signed-off-by: Daniel Kec <[email protected]>
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../src/test/java/org/glassfish/jaxb/runtime/v2/runtime/reflect/opt/ForeignAccessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Distribution License v. 1.0, which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
package org.glassfish.jaxb.runtime.v2.runtime.reflect.opt; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import jakarta.xml.bind.annotation.XmlAccessType; | ||
import jakarta.xml.bind.annotation.XmlAccessorType; | ||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
import org.glassfish.jaxb.runtime.v2.bytecode.ClassTailor; | ||
import org.glassfish.jaxb.runtime.v2.runtime.reflect.Accessor; | ||
import org.junit.Test; | ||
|
||
public class ForeignAccessorTest { | ||
|
||
/** | ||
* Foreign accessor shouldn't throw ClassCastException, just skip optimization. | ||
*/ | ||
@Test | ||
public void foreignAccessor() throws NoSuchFieldException{ | ||
String newClassName = EntityWithForeignAccessor.class.getName().replace('.','/') + "$JaxbAccessorF_author"; | ||
Class<?> foreignAccessor = AccessorInjector.prepare(EntityWithForeignAccessor.class, | ||
ClassTailor.toVMClassName(ForeignAccessorTest.FieldAccessor_Ref.class), | ||
newClassName); | ||
assertNotNull(foreignAccessor); | ||
|
||
Accessor<Object, Object> accessor = OptimizedAccessorFactory.get(EntityWithForeignAccessor.class.getDeclaredField("author")); | ||
assertNull(accessor); | ||
} | ||
|
||
@Test | ||
public void knownAccessor() throws NoSuchFieldException { | ||
Accessor<Object, Object> accessor = OptimizedAccessorFactory.get(EntityWithKnownAccessor.class.getDeclaredField("author")); | ||
assertNotNull(accessor); | ||
} | ||
|
||
@XmlRootElement | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
static class EntityWithKnownAccessor { | ||
String author; | ||
} | ||
|
||
@XmlRootElement | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
static class EntityWithForeignAccessor { | ||
String author; | ||
} | ||
|
||
/** | ||
* Test template doesn't extend accessor intentionally. | ||
*/ | ||
public static class FieldAccessor_Ref /*extends Accessor*/ { | ||
public FieldAccessor_Ref() { | ||
// super(Ref.class); | ||
} | ||
|
||
public Object get(Object bean) { | ||
return ((Bean)bean).f_ref; | ||
} | ||
|
||
public void set(Object bean, Object value) { | ||
((Bean)bean).f_ref = (Ref)value; | ||
} | ||
} | ||
} |