Buggy code:
public class AddSingleHealthDSUnit extends HttpServlet { public void processRequest ( HttpServletRequest request , HttpServletResponse response ) throws IOException , ServletException { response . setContentType ( "application//json" ) ; response . setCharacterEncoding ( "UTF-8" ) ; request . setCharacterEncoding ( "UTF-8" ) ; Users accessUser = null ; PermissionFilter filter = new PermissionFilter ( ) ; String loginID = filter . checkAndGetLoginFromToken ( request , response ) ; UserDAO userDao = new UserDAO ( ) ; if ( loginID == null ) { if ( filter . getCheckResult ( ) . equalsIgnoreCase ( filter . INVALID_LOGIN_TOKEN_ID ) ) { return ; } else if ( filter . getCheckResult ( ) . equalsIgnoreCase ( login_token_expired ) ) { return ; } else { ReturnParser . outputErrorException ( response , Invalid_login_token_id , null , null ) ; } } else { accessUser = userDao . getLogin ( loginID ) ; } PrintWriter out = response . getWriter ( ) ; try { SubjectDAO subjDao = new SubjectDAO ( ) ; Subject subject = ( ( Subject ) ( subjDao . findHealthSubject ( loginID ) ) ) ; if ( subject == null ) { try { subject = subjDao . createDefaultHealthSubject ( loginID ) ; HealthDataStreamDAO hdsDao = new HealthDataStreamDAO ( ) ; hdsDao . createDefaultDatastreamsOnDefaultSubject ( loginID , subject . getId ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; ReturnParser . outputErrorException ( response , Internal_Fault , null , null ) ; e . printStackTrace ( ) ; } } String streamTitle = ServerUtil . getHealthStreamTitle ( JsonUtil . ServletPath ( request ) ) ; DatastreamDAO dstreamDao = new DatastreamDAO ( ) ; DBtoJsonUtil dbtoJUtil = new DBtoJsonUtil ( ) ; Datastream datastream = null ; try { datastream = dstreamDao . getHealthDatastreamByTitle ( subject . getId ( ) , streamTitle , true , false ) ; } catch ( NonUniqueResultException ex ) { ReturnParser . outputErrorException ( response , Internal_Fault , null , streamTitle ) ; return ; } if ( datastream == null ) { ReturnParser . outputErrorException ( response , Unknown_StreamTitle , null , streamTitle ) ; return ; } if ( ! ( datastream . getOwner ( ) . equalsIgnoreCase ( loginID ) ) ) { ReturnParser . outputErrorException ( response , Unauthorized_Access , null , streamTitle ) ; return ; } JsonUtil jutil = new JsonUtil ( ) ; Gson gson = new Gson ( ) ; JsonDatastreamUnits junit = null ; String input = jutil . readJsonStrFromHttpRequest ( request ) ; try { junit = gson . fromJson ( input , JsonDatastreamUnits . class ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; ReturnParser . outputErrorException ( response , Input_Json_Format_Error , null , null ) ; return ; } try { DatastreamUnits unit = dbtoJUtil . convert_a_jdatastream_unit ( junit ) ; <START_BUG> if ( UnitValueTypes . existValueType ( unit . getValueType ( ) ) ) { <END_BUG> ReturnParser . outputErrorException ( response , Invalid_ValueType , Invalid_ValueType , unit . getValueType ( ) ) ; return ; } unit . setStreamID ( datastream ) ; dstreamDao . addSingleDS_Unit ( unit ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; ReturnParser . outputErrorException ( response , Internal_Fault , null , null ) ; return ; } datastream = dstreamDao . getHealthDatastreamByTitle ( subject . getId ( ) , streamTitle , true , false ) ; JsonDatastream jobject = dbtoJUtil . convertDatastream ( datastream , null ) ; JsonElement je = gson . toJsonTree ( jobject ) ; JsonObject jo = new JsonObject ( ) ; jo . addProperty ( result , succeed ) ; jo . add ( "datastream" , je ) ; JsonWriter jwriter = new JsonWriter ( out ) ; gson . toJson ( jo , jwriter ) ; System . out . println ( gson . toJson ( jobject ) ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; } finally { out . close ( ) ; } } @ Override protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws IOException , ServletException { } @ Override protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws IOException , ServletException { } @ Override public String getServletInfo ( ) { } }

Fix:
if ( ! ( UnitValueTypes . existValueType ( unit . getValueType ( ) ) ) ) {