Milestone 4 giving error

After implementing mainCalculateReturnsAfterRefactor() function in milestone 4, I tried to test it by the command given in todo ./gradlew run --args="trades.json 2020-01-01"
But this gives an error,

08:27:20.624 [main] ERROR com.crio.warmup.stock.log.UncaughtExceptionHandler - {"stacktrace":["java.net.URI.create(URI.java:852)","org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.createUri(DefaultUriBuilderFactory.java:400)","org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.build(DefaultUriBuilderFactory.java:393)","org.springframework.web.util.DefaultUriBuilderFactory.expand(DefaultUriBuilderFactory.java:205)","org.springframework.web.client.RestTemplate.execute(RestTemplate.java:676)","org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:345)","com.crio.warmup.stock.portfolio.PortfolioManagerImpl.getStockQuote(PortfolioManagerImpl.java:83)","com.crio.warmup.stock.portfolio.PortfolioManagerImpl.calculateAnnualizedReturn(PortfolioManagerImpl.java:102)","com.crio.warmup.stock.PortfolioManagerApplication.mainCalculateReturnsAfterRefactor(PortfolioManagerApplication.java:217)","com.crio.warmup.stock.PortfolioManagerApplication.main(PortfolioManagerApplication.java:289)"],"cause":"java.lang.IllegalArgumentException: Expected scheme-specific part at index 6: https:"}
java.lang.IllegalArgumentException: Expected scheme-specific part at index 6: https:
        at java.net.URI.create(URI.java:852) ~[?:1.8.0_242]
        at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.createUri(DefaultUriBuilderFactory.java:400) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
        at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.build(DefaultUriBuilderFactory.java:393) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
        at org.springframework.web.util.DefaultUriBuilderFactory.expand(DefaultUriBuilderFactory.java:205) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:676) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
        at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:345) ~[spring-web-5.2.2.RELEASE.jar:5.2.2.RELEASE]
        at com.crio.warmup.stock.portfolio.PortfolioManagerImpl.getStockQuote(PortfolioManagerImpl.java:83) ~[main/:?]
        at com.crio.warmup.stock.portfolio.PortfolioManagerImpl.calculateAnnualizedReturn(PortfolioManagerImpl.java:102) ~[main/:?]
        at com.crio.warmup.stock.PortfolioManagerApplication.mainCalculateReturnsAfterRefactor(PortfolioManagerApplication.java:217) ~[main/:?]
        at com.crio.warmup.stock.PortfolioManagerApplication.main(PortfolioManagerApplication.java:289) ~[main/:?]
Caused by: java.net.URISyntaxException: Expected scheme-specific part at index 6: https:
        at java.net.URI$Parser.fail(URI.java:2848) ~[?:1.8.0_242]
        at java.net.URI$Parser.failExpecting(URI.java:2854) ~[?:1.8.0_242]
        at java.net.URI$Parser.parse(URI.java:3057) ~[?:1.8.0_242]
        at java.net.URI.<init>(URI.java:588) ~[?:1.8.0_242]
        at java.net.URI.create(URI.java:850) ~[?:1.8.0_242]
        ... 9 more

FAILURE: Build failed with an exception.

I tried a lot to figure out the error but was unable to find it.
No such error came in all 3 milestones till now, I implemented calculateAnnualizedReturns , buildUri, getStockQuote in PortfolioManagerImpl, also both PortfolioManagerTest and PortfolioManagerFactoryTest were successful on it.
Please help!

Do you implemented readfileasString function ?

Illegal argument exception means you are passing wrong arguments to a function. You can run a debugger test to get the exact line where this error is occurring. Also ensure the argument types are correct.

Thanks! the problem was with readfileasstring function implementation.

what did u do exactly ?

Read the json file content as String and pass that string to object mapper.

1 Like

@jayansh @shubhamkumar27 do I need to implement readfileasString function from scratch as I no where got it’s boiler plate

You can resolve and process file on your own as you had done in previous milestones. And you can comment out readfileasstring function.

1 Like

thanks I resolved it , it helped :slight_smile: