2

I have following code in one of my tests:

List<Long> wordList = wordService.listAll().stream()
                                         .map(StudiedWord::getId)
                                         .collect(Collectors.toList());

StudiedWord is a POJO with Lombok:

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
public class StudiedWord extends AbstractModelClass {
    private String text;
    private String translation;
    private WordStage stage;
    private String image;
    private String sound;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
abstract class AbstractModelClass implements ModelObject {
    @Id
    @GeneratedValue
    private Long id;
}

I can run tests from IntelliJ IDEA and everything is OK. I can run tests manually from a terminal using Gradle and again everything is OK.

But on Travis I constantly get following error:

WordSetControllerTest > deleteWordSet FAILED
    java.lang.IllegalAccessError at WordSetControllerTest.java:255

The 255th line is the line with map statement and method reference. If I replace method reference with lambda expression (studiedWord -> studiedWord.getId()) then again everything is fine.

Here is content of my .travis.yml:

language: java
jdk:
  - oraclejdk8

Here is an example of my tests structure:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@WebAppConfiguration
@Slf4j
public abstract class MockMvcBase {
    /// common fields and methods for mock mvc tests
}

@Transactional
public class WordSetControllerTest extends MockMvcBase {
    @Autowired
    private WordService wordService;
    @Autowired
    private WordSetService wordSetService;

    // other methods
    @Test
    public void deleteWordSetById() throws Exception {
        // test logic
        List<Long> wordList = wordService.listAll().stream()
                                         .map(StudiedWord::getId)
                                         .collect(Collectors.toList());
        // assertions
    }
}

I have other tests where I use method references for other Lombok-generated methods and they work fine.

Is it problems with my Travis configuration or what am I missing?

solomkinmv
  • 1,804
  • 3
  • 19
  • 30
  • I know it may be naive, but are you by any chance using openjdk on your local machine? – Mateusz Chrzaszcz Jul 21 '17 at 22:09
  • Hi, where is your `WordSetControllerTest`? you hide the primary thing. – holi-java Jul 21 '17 at 22:11
  • @holi-java I've added some information about test class. Is it enough? – solomkinmv Jul 21 '17 at 22:18
  • @MateuszChrzaszcz I've double checked JDK. It is Oracle JDK – solomkinmv Jul 21 '17 at 22:22
  • @solomkinmv try to check exact oraclejdk version on travis that is being used (8uMINOR_VERSION), download it and try to reproduce on your machine. You could potentially find a bug in one of JDK versions ;) – Mateusz Chrzaszcz Jul 21 '17 at 22:24
  • Hi, have you try introduce a variable for the method reference expression? e.g:`Function mapping= StudiedWord::getId`. then using `.map(mapping)` to test against travis, maybe the oraclejdk8 doesn't support generic very well on travis. – holi-java Jul 21 '17 at 22:41
  • @holi-java how come? It should not matter if it is travis or not, the only thing we should care about here is oraclejdk8, am I wrong? – Mateusz Chrzaszcz Jul 21 '17 at 22:46
  • @MateuszChrzaszcz you are right. what I said is let you to test the jdk on travis and see it is whether works fine with method reference expression. – holi-java Jul 21 '17 at 22:49
  • 2
    @MateuszChrzaszcz looks like you were right. I've tested locally the same java 8 version as in Travis (1.8.0_31) and it failed. Looks like it was a bug. Then I've specified `dist: trusty` to get newer jdk version and now everything works fine. Thanks! – solomkinmv Jul 21 '17 at 22:55
  • @solomkinmv Cool! holy crap, you actually have an opportunity to raise a bug in JDK :D – Mateusz Chrzaszcz Jul 21 '17 at 22:56
  • @MateuszChrzaszcz I think there was a bug and it was fixed, otherwise it would still fail on recent builds of jdk8. So, nothing to raise :) – solomkinmv Jul 21 '17 at 22:59
  • @solomonkinmv It is fixed in a newer version, that's true, but this bug might actually be a potential danger to people using this JDK version (we do not exactly know what happens underneath) that's why it might be worth to consider doing that. – Mateusz Chrzaszcz Jul 21 '17 at 23:01

0 Answers0