Assuming you do not have any extra attacks involved, can you start your turn holding a 2-handed weapon with one hand, use your free object interaction to draw a javelin, then throw the javelin with your attack and return your hand to your 2-handed weapon for opportunity attacks (such as granted by Polearm Master)?
The difference between this and other questions is the javelin will no longer be in your hand at the end of your turn so the meat of it is can you put your now empty hand back on the two handed weapon so you can use said weapon for opportunity attacks before your turn ends or not.
Scenario 1. As described holding 2h weapon in one hand. Draw javelin, throw javelin, place second hand on 2h weapon. Is that legal to do in one turn?
Scenario 2. If no to scenario one, would the answer change if you started your turn holding 2h weapon in one hand and javelin in the other? I’m almost positive this setup would work because your free object interaction would be grab 2h weapon with both hands.