Some Trials & a lot of Errors
I tried a bunch of framework and other language and I usually feel overwhelm when its time to do something real with what I've learned. So that why I created this site, to write my progress and help some noob like me that stumble into the sames problems.
Browse: Home / java

java

How to gzip a file in Java using Files.copy

By Chris on December 13, 2022

We needed our compress files generated from our apps at work and I went the old way using a fileInputStream and a fileoutputStream: private static void compressFileToGzipOldWay(File destinationDir, File fileToCompress) throws IOException { String compressedFilesName = fileToCompress.getName() + “.gz”; File compressedFileDir = new File(destinationDir, compressedFilesName); FileInputStream fis = new FileInputStream(fileToCompress.getName()); FileOutputStream fos = new FileOutputStream(compressedFileDir); […]

Posted in java | Tagged gzip, java | Leave a response

How to remove array element in mongodb in java?

By Chris on June 17, 2021

In the previous post, we discuss own we change from using mongorepository to using directly mongodb method to access and modify directly the object in db.In this posts we look at code that was deleting with mongorepository and change it to use directly mongodb method with MongoTemplate. Using MongoTemplate is faster and less likely to […]

Posted in java, mongodb, prog, tips | Tagged java, mongodb, MongoRepository, MongoTemplate | Leave a response

How to update an entry in an array in mongodb with java MongoTemplate?

By Chris on June 10, 2021

We had at work a piece of code that was using mongorepository and updating the arrays of the object on a collection instead of using mongodb method directly.The way it was coded had a big issues with concurrency and we were losing update because of it.The problem we had with the way it was updating […]

Posted in java, mongodb, prog, tips | Tagged java, mongodb, MongoRepository, MongoTemplate | 1 Response

Assert an Exception is Thrown in JUnit 4 and 5

By Chris on May 19, 2021

This is old news, but having work with big bank and insurance companies they tend to stick with the old version of java and they’re underlying libraries, I’ve finally been expose to new ways of testing exception with junit. I use to test exception by adding an expected right after the @Test annotation.@Test(expected = NullpointerException) […]

Posted in java | Tagged assertJ, java, junit, junit4, junit5, mokito, testing | Leave a response

Solving LazyInitializationException with sonar rules @Transactional method called from another method doesn’t obtain a transaction

By Chris on May 12, 2021

We recently added a feature that allowed direct modification on our content for some client vs using the same path (queues) that the batched content is using. Our user were really happy with it, but after our team implemented the new feature, we started having some LazyInitializationException. exception for that problem org.hibernate.LazyInitializationException: could not initialize […]

Posted in java | Tagged Exception, hibernate, java, LazyInitializationException | Leave a response

Why does Map.of not allow null keys and values?

By Chris on March 2, 2021

Once upon a time an engineer with years of experience encounter something so basic he doesn’t understand why he didn’t encounter it sooner. This week we had a strange error in our log stating that should have a null values in a map. After some digging in the service where that log was found, it […]

Posted in java | Tagged java, java.util.Map, maps, null | Leave a response

Constructor XXX in enum XXX cannot be applied to given types in mapstruct

By Chris on May 20, 2020

I was having that weird error when I was working with mapstruct, turn out that the default java version for mapstruct is java 6. Since our project was in java 11 I was getting the error “Constructor XXX in enum XXX cannot be applied to given types”. My starting config was : <dependencies> <dependency> <groupId>org.mapstruct</groupId> […]

Posted in error, java | Tagged java, java8, mapstruts, maven | Leave a response

List Return a java.lang.UnsupportedOperationException when adding or removing a element

By Chris on October 12, 2014

While trying to remove a element after creating a List from a array using the Array.asList(array[]) method I’ve stumbled on that error. java.lang.UnsupportedOperationException at java.util.AbstractList.add(AbstractList.java:131) at java.util.AbstractList.add(AbstractList.java:91) Then I remember this, list created by the Arrays.asList method are immutable Same goes for empty lists. So instead create a arraylist : List<String> list = new ArrayList<String>(Arrays.asList(split));

Posted in java, prog | Tagged arraylist, java, java.util.List | Leave a response

JENKINS: How to fix a java.net.NoRouteToHostException.

By Chris on October 5, 2014

Our build server (jenkins) had that error   BUILD FAILED com.jcraft.jsch.JSchException: java.net.NoRouteToHostException: No route to host Full stack trace below if you really need it. I assume there was a problem with where Jenkins was deploying the apps or at a issue trying to run integration test on the remote server. After talking to IT […]

Posted in prog | Tagged build server, java, jenkins | Leave a response

Why is String not sorting with the Local ?

By Chris on September 28, 2014

Comparing and sorting Strings might not work out like you expected specially when your dealing with a language other than English. Normally comparing strings in done with simple Unicode ordering. If you want to have localized ordering (the kind expected by an end user) you need to use a Collator. Commonly used String methods such […]

Posted in java, prog | Tagged collator, java, sorting, String | Leave a response

Next »

Tags

2018 2022 app apparment baby book books cleaner date daycare db fantasy draft fantasy sports food foods fridge games gifts grocery hibernate hockey hockey pools ideas inspiration java java.util.List learning List meal plan meal planner motivation mysql oracle productivity retail shopping reviews service social games sql String students The Practice to_date uber wedding

Recent Comments

  • pawan on How to update an entry in an array in mongodb with java MongoTemplate?
  • kevin on Oracle have no Boolean, how to fix this

Calendar

March 2023
MonTueWedThuFriSatSun
 12345
6789101112
13141516171819
20212223242526
2728293031 
« Dec  

Archives

  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • March 2021
  • February 2021
  • May 2020
  • January 2019

Copyright © 2023 Some Trials & a lot of Errors.

Powered by WordPress and Hybrid.