Giter VIP home page Giter VIP logo

Comments (6)

mygoaway avatar mygoaway commented on June 28, 2024 1

넵, 저도 버전 변경에 따른 리플렉션이 원인이 아닐까?라는 추측은 하긴하였습니다.
여튼 해결책 빨리 말씀주셔서 감사합니다.

from fixture-monkey.

seongahjo avatar seongahjo commented on June 28, 2024

안녕하세요. @mygoaway

일단 원인부터 말씀드리면, 픽스쳐 몽키에서는 인터페이스가 입력되는 경우 다른 설정이 없다면 자동으로 익명 객체를 생성해줍니다.
MultipartFile 내부에 getResource 메소드의 반환 값인 Resource를 생성하고, Resource 내부에 getFile 메소드의 반환 값인 File을 생성할 때 이슈가 발생하고 있습니다.

기본으로 설정하신 Introspector인 FieldReflectionArbitraryIntrospector은 빈 생성자를 사용해 인스턴스를 생성하고, 리플렉션을 통해 값을 변경하는 방식으로 객체를 생성하고 있습니다. 문서 참조
File은 빈 생성자가 존재하지 않아 FieldReflectionArbitraryIntrospector 으로는 생성할 수 없습니다.

원하시는 의도에 따라 해결하는 방법이 달라질 것 같습니다.

MultipartFile가 필요가 없는 경우

private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
        .objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
        .pushAssignableTypeArbitraryIntrospector(
			MultipartFile.class,
			it -> new ArbitraryIntrospectorResult(CombinableArbitrary.from((Object)null))
         )
        .build();

MultipartFile가 테스트에서 필요하고, 원하시는 구현체가 있는 경우

private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
        .objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE)
        .pushAssignableTypeArbitraryIntrospector(
			MultipartFile.class,
			it -> new ArbitraryIntrospectorResult(CombinableArbitrary.from(new MultipartFileImpl())
         )
        .build();

필요하신 다른 케이스가 있으시면 말씀해주시면 방법을 공유드리겠습니다.
감사합니다.

from fixture-monkey.

mygoaway avatar mygoaway commented on June 28, 2024

아, 넵! 말씀주신대로 작업하니 문제없이 처리되네요.
추가적으로 한가지 더 질문드려도 괜찮을까요?
기존 자바 8에서는 문제 안되다가 최근 프로젝트를 자바 11버전으로 업그레이드한 이후 해당 문제가 발생했는데 혹시 해당 이유도 알 수 있을까요?

from fixture-monkey.

seongahjo avatar seongahjo commented on June 28, 2024

@mygoaway
해결이 돼서 다행이네요 😄 혹시 자바11로 업그레이드하시면서 스프링 버전도 업그레이드 하셨을까요?
지금 문제가 된 메소드가 spring-web 5.1 버전부터 추가됐는데, 그 영향일 가능성이 커보입니다.

from fixture-monkey.

mygoaway avatar mygoaway commented on June 28, 2024

스프링 버전은 변경하지 않았습니다. 2.3.0 버전 사용중에 있습니다.

from fixture-monkey.

seongahjo avatar seongahjo commented on June 28, 2024

그럼 정확한 원인을 공유드리기는 어려울 것 같습니다.
일단 픽스쳐 몽키에서는 multi release가 적용이 되있어서 JDK 버전마다 동작이 달라지긴 하는데요, JDK 17에만 대응하고 있습니다. JDK11에서는 동작이 모두 동일합니다.

제 추측을 말씀드리면, JDK 버전이 변경되면서 리플렉션 동작이 달라져서 생긴 이슈일 것 같다는 생각이 듭니다.
JDK vendor마다 리플렉션 구현이 조금씩 다르다고 알고 있습니다. 실제로 리플렉션을 통해 조회한 생성자, 메소드 순서가 JDK vendor마다 다릅니다.

from fixture-monkey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.