These days, in the practice of ShardingSphere, this is not another problem well, when the start of the report of an NPE out.
Fortunately, this problem does not affect the use, but the start will report a point error, and then, it is a hard troubleshooting process.
Directly locate to the place where the error is reported, find that ShardingSphere at startup to load some metadata information error report, see this place is obviously guessed that the map to get when reporting the error.
A link to the source code up, found that the definition here is TreeMap, that should be no problem, that is, the above dataType is a null, so the report is wrong, but I am still young.
We have already located where the problem occurs, so let’s analyze why this problem occurs.
As you can see from the source code, it is mainly in this place to load the metadata information of the columns of the database table.
In this class, concatenated SQL query statements are found, mainly to look up the columns table below information_schema.
At this time, I wanted to see what this was all about, so I opened the local debug to see that there was no problem, and then went to the test environment to find that there was no problem, as if only the production had this problem.
This dataTypeMap is a mapping of column types, but there is no way to reproduce it locally.
If there is no way to do it locally, then according to the above SQL to the production library to see what is wrong with the field of the COLUMNS table, query a look, found a lot of nulls, and some other messy types, then it seems that the reason for NPE is because of these nulls.
So where do these null values come from? Based on troubleshooting findings, they are all generated by views from the TIDB. The local and test has no way to reproduce because its practical is Mysql.
This environmental problem is quite disgusting, because there is no TIDB environment, you can only install one to find a way to reproduce it (the process is very time-consuming).
Fortunately, it is still very convenient to install these things on the Mac, install, refresh the environment variables, and start.
Then the local according to the very sand sculpture to create a view of the way to create a view out, and then local DEBUG look.
Come in and see, and the beginning of the thought is not the same, it is actually a null string, not the null I imagined, then this does not look like it should be a null pointer?!
A little confused as to why this place will be empty, and then open this class to take a look.
Could it be unboxing?
Well, that’s right. dataTypeMap.get(dataType) is null, what is the unboxing call I don’t need to say it, that’s why…
What do you say?
Some students said, that is not simple, are you a sand sculpture? Changing to Integer isn’t the end of the day.
Well, you’re right, I just changed that.
Then, after the correction, the startup is a bunch of errors, and there are calls everywhere.
This thing can’t move, as if to tell me, you try to move, and if you move, you will die.
The article is written here, I have not yet thought about how to change, there are about 3 programs:
Give them a chance to give them a PR.